Re: method called from different threads(?) using a lock
Re: method called from different threads(?) using a lock
- Subject: Re: method called from different threads(?) using a lock
- From: John Stiles <email@hidden>
- Date: Tue, 22 May 2007 17:48:56 -0700
I don't think it would be safe to do this from a thread, even if you
have a lock. Have you tried performOnMainThread?
Mitchell Livingston wrote:
Hello,
I have a "badger" class to badge the dock icon with a download speed
and completed count (it's a downloader app). I have a single instance
of the class, where an NSLock is initialized in the init function.
The main method of the badger is called constantly by a timer that
runs in the current run loop in multiple modes; this works fine in
updating the badge. The whole method is protected by the lock (I lock
at the beginning and unlock and the end).
The problem occurs when a method in my controller class is called
from either a window delegate or a notification. The method called
essentially calls the same main method in the badger class with a new
value for completed count. However, this is not reflected in the dock
icon. It seems that the lock does not work (I tested with tryLock and
it never returned NO), and as a result the critical section of the
badger class is run twice at the same time, causing the badge to not
be updated correctly.
Is there something that I did wrong with the lock? Does it have
anything to do with being the same instance of the badger being
called from multiple threads? Or is it something else entirely? Any
help would be appreciated.
Thanks,
Mitchell Livingston
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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