Re: IOCommandGate vs ISyncer
Re: IOCommandGate vs ISyncer
- Subject: Re: IOCommandGate vs ISyncer
- From: Chris Sarcone <email@hidden>
- Date: Wed, 13 Aug 2008 10:27:53 -0700
Duane --What is the recipe for this seemingly simple task (that IOSyncer handles very nicely) with IOCommandGate.
Easy recipe:
Sync Call is made done = false; Send I/O asynchronously IOCommandGate::runAction() while (!done) IOCommandGate::commandSleep(&done,TH_UNINT);
On workloop completion thread: done = true; IOCommandGate::commandWakeup(&done);
This is very similar to other condition variable like constructs. PThreads programmers will be familiar with this (pthread_mutex_lock()/pthread_cond_wait()/pthread_cond_signal()).
NB: The predicate loop of "while (!done)" is extremely important. An "if" check is insufficient.
Note also that this same thing can be done with a mutex lock and using the sleep/wakeup variants of those (i.e. IOLockSleep()/IOLockWakeup()). Using the IOCommandGate construct makes the taking of the lock "free" on the completion side since the completion should be made with the workloop lock held (and the setting of done = true atomic).
HTH,
-- Chris
------------------ 6 Infinite Loop M/S 306-2MS Cupertino CA 95014 phone: (408) 974-4033 fax: (408) 862-7577 email: email@hidden |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden