• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Stuck notes in Rax and Synthtest
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stuck notes in Rax and Synthtest


  • Subject: Re: Stuck notes in Rax and Synthtest
  • From: Chris Reed <email@hidden>
  • Date: Wed, 7 May 2003 13:56:41 -0500

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.

  • Follow-Ups:
    • Re: Stuck notes in Rax and Synthtest
      • From: Garth Cummings <email@hidden>
    • Re: Stuck notes in Rax and Synthtest
      • From: Art Gillespie <email@hidden>
References: 
 >Re: Stuck notes in Rax and Synthtest (From: Art Gillespie <email@hidden>)

  • Prev by Date: Re: Stuck notes in Rax and Synthtest
  • Next by Date: Re: Stuck notes in Rax and Synthtest
  • Previous by thread: Re: Stuck notes in Rax and Synthtest
  • Next by thread: Re: Stuck notes in Rax and Synthtest
  • Index(es):
    • Date
    • Thread