Re: Stuck notes in Rax and Synthtest
Re: Stuck notes in Rax and Synthtest
- Subject: Re: Stuck notes in Rax and Synthtest
- From: Art Gillespie <email@hidden>
- Date: Wed, 7 May 2003 17:46:48 -0400
From TN2028
"User-space processes should not create Mach threads directly."
And...
"In general, it is not appropriate to make Mach thread calls on
pthreads. Some exceptions are the Mach APIs for getting thread
information, setting up thread exception handlers, and death
notification, which should work for any Mach thread regardless of how
it was created."
So, as a plug-in, it's fair to assume that the host isn't using Mach
threads directly, or at least that they shouldn't be... given this and
the fact that you shouldn't make Mach thread API calls from
higher-level API threads (pthread, NSThread, etc.), I assumed this was
a bad idea.
Best,
Art
>>0xBA
On Wednesday, May 7, 2003, at 02:56 PM, 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
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.