Re: Thread Communication Conceptual Question
Re: Thread Communication Conceptual Question
- Subject: Re: Thread Communication Conceptual Question
- From: Filipe Varela <email@hidden>
- Date: Thu, 2 Aug 2007 11:22:53 +0100
Chris, you're positively right as far as Cocoa apps go. There's no
need to get to the low-level uglyness i described. It's confusing and
unpredictable. But since i noticed it happened on my code
(unintentionally - i was trying something else), i thought i'd
mention it.
Now this is a Cocoa list so this could get off-topic real quick. But
ever since i began investigating how signal masking could be used in
c-only i have become quite enthusiastic about it. Remember, he wants
a non-cocoa dependent piece of code.
Moving a bit closer to topic:
In this case, you could use a simple function with a pointer to the
data and a mutex to signal availability/change of data.
ie, main thread loop:
test mutex (non blocking test&set) {
// got here? we're unlocked
if data messed flag is set {
do stuff on data
unset flag
}
}
keep exec'ing loop
data producer/updated thread loop:
mess with work data
need to signal update? {
lock mutex
copy work data to shared data
set data messed flag to true
unlock mutex
}
I use this to track download progress in a plain ansi-c downloader
context.
The data messed flag is used to prevent the main thread to exec stuff
on data more often than necessary because it's possible to get an
unlocked mutex without having a data change...
Cheers,
Filipe
On 02/08/2007, at 7:45 PM, Andrew Farmer wrote:
On 02 Aug 07, at 02:42, Filipe Varela wrote:
AFAIK, and based on something i wrote (check out www.dev6.com
under the blog section, release 1 of the flightcontroller code),
if you do signal handling, the signal handler is always executed
on the main thread. Could that be used to pass messages to the
main thread in your case?
Apart from being an awful way to do things, I believe it's also wrong:
http://developer.apple.com/qa/qa2001/qa1184.html
and even if it wasn't wrong, there'd be no guarantee the behaviour
would stay that way.
- Chris
_______________________________________________
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