From: bert hubert (ahu_at_[hidden])
Date: 2004-10-02 06:14:56
On 2004-10-01, Parameswaran, Vinod <vparameswaran_at_[hidden]> wrote:
> 2. Does anyone have some examples of scenarios wherein each of these
> classes could be used (would even appreciate reference to relevant
> docs., if any):
> a. barrier
Never used this.
> b. condition
This can be used to broadcast things to other groups - a thread might want
to wait for a number of events to become available for example
> c. thread_group
This is a boost concept which allows one to wait on several threads
simultaneously - pretty well documented.
> d. thread_specific_ptr
I didn't know boost threads provided this. Consider this function:
char *getSomething(int var)
// do stuff that fills buffer
This is fine in a singlethreaded world but you enter a world of pain if you
do this in an environment where other threads might be calling getSomething
at the same time - there is only 1 buffer to work with, and all of them
will scribble it at the same time!
Thread specific storage makes sure that each thread has its own static
> 3. Assumption: In the case of a condition object, ONLY THE FOLLOWING
> METHODS could be used to specify the wait condition:
> Is this correct?
> 4. <begin quote>
> A thread object has an associated state which is either
> "joinable" or "non-joinable".
> <end quote>
> Is this state indicated using a type or is merely implied by whether the
> default or the parameterized constructor is called for the creation of
> the thread object?
A thread can detach itself and become non-joinable. This saves memory. I
think a thread group manages this for you.
> 5. Could anyone give examples of the use of void join() and void
> yield()? (Would even appreciate reference to relevant docs., if any)
This is from a real program. Yield() has somewhat varying semantics but
generally means 'give up this timeslice'. When busywaiting on something,
yield() yields the CPU to other threads or processes.
> 6. <begin quote>
> Template thread_specific_ptr stores a pointer to an object obtained via
> new on a thread-by-thread basis and calls delete on the contained
> pointer when the thread terminates. Each thread initially stores the
> null pointer in each thread_specific_ptr instance.
I haven't been able to answer all your questions but I hope this helped
-- http://www.PowerDNS.com/ Open Source Database Driven Nameserver http://lartc.org Linux Advanced Routing & Traffic Control HOWTO
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk