Re: NSLock locking order;
Re: NSLock locking order;
- Subject: Re: NSLock locking order;
- From: Alastair Houghton <email@hidden>
- Date: Mon, 14 Nov 2005 17:21:58 +0000
On 14 Nov 2005, at 17:09, Shawn Erickson wrote:
On Nov 14, 2005, at 8:47 AM, Matt Budd (Madentec) wrote:
Hey Alastair,
Thanks for the tip...this actually works great. By setting a
regular boolean instance variable, I am in effect defining a queue
order for the worker thread. So the main thread is blocking
waiting to be allowed to update the state, but the worker thread
won't continue if there is this update waiting. This works even if
the worker thread gets swapped in a couple of times before the
main thread can get back to updating the state.
I'm still wondering why this works and just locks doesn't, but I
guess it is because the lock by itself is not enough to signal
order and we have to add this extra flag.
Consider leveraging a read / write lock if your start to get into
multiple threads (not knowing exactly your usage model). You can
use what exists at the "darwin" layer for this purpose and even
wrap it with a nice Objective-C object if you want... likely can
find one out in the wild. Review the following...
<http://developer.apple.com/documentation/Darwin/Conceptual/
KernelProgramming/synchronization/chapter_15_section_4.html#//
apple_ref/doc/uid/TP30000905-CH218-CJHFIAEH>
:-) I was about to say something very similar.
I'd be interested to know if anyone has any recommendations for books
on threaded programming BTW; "Programming with POSIX Threads" looks
quite good and seems to have some practical sections. I haven't read
it though.
Kind regards,
Alastair.
--
http://www.alastairs-place.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden