• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Compile error using @synchronized on methods that return values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Compile error using @synchronized on methods that return values


  • Subject: Compile error using @synchronized on methods that return values
  • From: Ken Tozier <email@hidden>
  • Date: Sun, 8 Nov 2009 06:03:18 -0500

Hi

I wrote a MySQL connection class and have found that when I use the accessors in multiple threads, the query results seem to be stomping on each other. I looked into using @synchronized(self) to bracket the calls to the lower level socket calls, I'm getting the following warning:

"Control reaches end of non-void function"

I Googled for "Objective-C accessors and @synchrinized" which seemed to indicate that the following was the correct way to handle it

- (id) someMethod
{
	@synchronized(self)
	{
		return [somevalue autoreleae];
	}
}

But I get the above error whenever I try to do it that way. Here's one of the actual methods with and without the @synchronized directive

- (NSString *) directoryPathWithType:(NSString *) inDirectoryType
site:(NSString *) inSiteName
{
NSString *query = [NSString stringWithFormat: @"select id from directory where name=' %@' and type='%@'", inSiteName, inDirectoryType];

id queryResult = [connection performQueryReturningOne: query];

return [[queryResult objectForKey: @"path"] value];
}



- (NSString *) directoryPathWithType:(NSString *) inDirectoryType
site:(NSString *) inSiteName
{
@synchronized(self)
{
NSString *query = [NSString stringWithFormat: @"elect id from directory where name=' %@' and type='%@'", inSiteName, inDirectoryType];

id queryResult = [connection performQueryReturningOne: query];

return [[queryResult objectForKey: @"path"] value];
}
}


I understand why, under normal circumstances, that nesting would yield the above mentioned compiler error, but I don't understand why every example I've been able to find on the web says to do exactly that type of @synchronized nesting. What is the correct way to make the above function thread safe?

Thanks for any help
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Compile error using @synchronized on methods that return values
      • From: "Adam R. Maxwell" <email@hidden>
    • Re: Compile error using @synchronized on methods that return values
      • From: Dave Keck <email@hidden>
  • Prev by Date: Re: Pausing an NSThread
  • Next by Date: Re: Compile error using @synchronized on methods that return values
  • Previous by thread: Odd QuickLook generator UTI specification feature/bug
  • Next by thread: Re: Compile error using @synchronized on methods that return values
  • Index(es):
    • Date
    • Thread