Re: Stuck notes in Rax and Synthtest
Re: Stuck notes in Rax and Synthtest
- Subject: Re: Stuck notes in Rax and Synthtest
- From: Garth Cummings <email@hidden>
- Date: Thu, 8 May 2003 08:00:33 -0700
Hi Chris,
On Wednesday, May 7, 2003, at 11:56 AM, Chris Reed wrote:
Except that you probably want to be using the Mach semaphores
(mach_semahore_t) instead pthread mutexes (which are built on the Mach
primitive), since the Mach sems feature nonblocking signaling.
-chris
A cautionary note...
We generally recommend that developers not use Mach APIs directly. We
don't guarantee that they won't change, unlike higher-level APIs. Most
of our frameworks have higher-level wrappers around Mach calls that
preserve the abstraction layering.
There may be cases when there's no other way to accomplish something.
If you find one of those cases, I suggest filing an enhancement request
to add an API to the framework you're using at
<
http://developer.apple.com/bugreporter>.
Thanks,
--gc
On Wednesday, May 7, 2003, at 12:18 US/Central, Art Gillespie wrote:
Could anyone briefly explain a newbie what a mutex is and how it's
used? (A link would do)
Mutex = Mutual Exclusion
- Serializes access to a critical region of code or data.
void importantShitThatNeedsToBeSerialized ()
{
/**
* Note this will block if the lock is already in use
* If you can't afford this behavior (e.g. in a realtime thread),
* use pthread_mutex_trylock and check the return value for EBUSY
* In either case NEVER call pthread_mutex_unlock unless
pthread_mutex_lock
* returned 0.
*/
pthread_mutex_lock(myMutex);
// do important shit here
pthread_mutex_unlock(myMutex);
}
(see man pthread_mutex_lock, man pthread_mutex_trylock, and man
pthread_mutex_unlock for more)
Create your mutex -
pthread_mutex_t myMutex = PTHREAD_MUTEX_INITIALIZER;
- or with -
int pthread_mutex_init ( pthread_mutex_t *mutex, pthread_mutexattr_t
*attr);
(see man pthread_mutex_init for more)
Destroy your mutex -
int pthread_mutex_destroy (pthread_mutex_t *mutex);
(see man pthread_mutex_destroy for more)
Note that the case may arise where you need mutual exclusion that
*isn't* owned by the locking thread... in this case, you need to use
a semaphore instead. (Since semaphores aren't part of Pthreads,
you'll have to look into BSD's compliance with POSIX 1003.1b-1993).
Semaphores are cool for work queues/synchronization because you can
have a bunch of threads *park* on a semaphore and when there's
something ready for them to do, another thread can notify the
semaphore that either one or all of the waiting threads can continue.
Hope that helps.
Best,
Art
>>0xBA
Cheers,
;) Urs
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.