Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: pthread code I may use
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pthread code I may use



Hi Theodore,

I don't think this will work.

http://www.hmug.org/man/3/pthread_mutex_unlock.php

You can't unlock a mutex from a thread other than the one that locked it. You need semaphores instead! Generally speaking:

- Use mutexes to protect access to shared data between multiple threads (to "lock" data).

- Use semaphores to cause one thread to wait until another thread has provided a resource. When one thread is READING/CONSUMING data that another is WRITING/PRODUCING, a semaphore is a good idea. (Caps because these are the terms by which you'll hear this kind of thing discussed in comp-sci lit...)

http://en.wikipedia.org/wiki/Producers-consumers_problem

I chose this double lock design, because in theory... it will mean I don't need to create and destroy threads all the time! I can keep on using the main thread. And this... I think... should be more CPU efficient, than a lock, correct?

You are right to keep the worker thread around and not create and destroy threads all the time, assuming you can keep your total thread count down to something sane (not 10000 threads).


cheers
Ben


-- Scenery Home Page: http://scenery.x-plane.com/ Scenery blog: http://xplanescenery.blogspot.com/ Plugin SDK: http://www.xsquawkbox.net/xpsdk/ Scenery mailing list: email@hidden Developer mailing list: email@hidden _______________________________________________ Do not post admin requests to the list. They will be ignored. PerfOptimization-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >pthread code I may use (From: "Theodore H. Smith" <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.