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 18:06:54 -0700
If performOnMainThread did not work, your problem is unrelated to
locking or threading, because there is no way for the main thread to
be doing two things at once.
When you say "the badge is not updated correctly," what exactly are
you observing? I have seen rare instances where dock badge updating
just stops functioning entirely in an app until it is quit, but I
haven't found any rhyme or reason to it.
On May 22, 2007, at 6:00 PM, Mitchell Livingston wrote:
I did with no luck. I then tried firing the trigger instead of
calling it separately, still with no luck.
On Tuesday, May 22, 2007, at 08:49PM, "John Stiles"
<email@hidden> wrote:
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:
40blizzard.com
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