Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Semaphores HOWTO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Semaphores HOWTO



On Oct 6, 2003, at 04:31 PM, Mark Thomas wrote:

I was thinking that I my code would initially create a semaphore with max
and initial to 10, so any of the other threads would immediately block, and
then after all setup was done, would call MPSignalSemaphore 10 times, to
make it free to all the threads, which I guess should be, as I'm using this
semaphore to control the threads to wait until and setup is ready, and the
data which they need to be available.

Initial set to 0 at least =) (it's great when you unintentionally make an error - even greater when your trying to help someone else!). If you data that you need to prepare for each thread however, you may be better served with MPQueues. Similar concept, but instead of just sending a signal that the resources is available, they actually provide the resource your waiting on. This way you might be able to get some of those threads working while your still prepping data for other threads. And if all the threads are symmetric (probably not your situation from what you've stated) then you can just let them arbitrarily handle data from a shared queue.

Also is there a way to have a thread to block on a semaphore and event
together or n MP objects. I use wait on Object on Win32, which works great
to wait for a few differen't things to happen.

There are many approaches to this, but there isn't OS support for it directly AFAIK. The simplest solution is to do a timed cascade wait through all the objects you want to wait on (MPWaitOnXXX for less than forever, then wait on another, and another, etc). Of course, this requires you to know what your waiting on exactly. There is also the option of using an MPQueue instead of the individual waits and using the parameters for notifications. The solution you settle on will probably depend entirely on what your requirements are.
--
Reality is what, when you stop believing in it, doesn't go away.
Failure is not an option. It is a privilege reserved for those who try.

David Duncan
_______________________________________________
mt-smp mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/mt-smp
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Semaphores HOWTO (From: Mark Thomas <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.