user4951
user4951

Reputation: 33140

What is wrong with this locking scheme

for (NSString * district in allLinedStrings) {
    PO1(district);
    [self.mainLock lock];
    CLGeocoder * geocode= [[CLGeocoder alloc]init];
    [geocode geocodeAddressString:district completionHandler:^(NSArray *placemarks, NSError *error )
     {
         for (CLPlacemark * thePlace in placemarks)
         {
             [self handlePlacemark:thePlace];

         }
         [self.mainLock unlock];
     }];
}

I want to run geocodeAddressString synchronously and I do this. Somehow I got error of deadlock. But what's wrong?

Upvotes: 1

Views: 169

Answers (1)

Parag Bafna
Parag Bafna

Reputation: 22930

If you are using NSLock: Calling the lock method twice on the same thread will lock up your thread permanently.

for (NSString * district in allLinedStrings) {
    PO1(district);
    [self.mainLock lock];
    CLGeocoder * geocode= [[CLGeocoder alloc]init];
    [geocode geocodeAddressString:district completionHandler:^(NSArray *placemarks, NSError *error )
     {
         for (CLPlacemark * thePlace in placemarks)
         {
             [self handlePlacemark:thePlace];

         }

     }];
[self.mainLock unlock];
}

Upvotes: 1

Related Questions