Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::thread Compile error with Sun Studio 12
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2009-05-29 03:23:14


Roman Morokutti <roman.morokutti_at_[hidden]> writes:

> Anthony Williams wrote:
>> If you declare variables "extern" at block scope then you need to
>> provide a declaration at global scope too.
>>
>> The point of declaring them extern in the example is to say that these
>> variables are accessible to, and used by, code elsewhere in the
>> system. In particular, another thread will lock the mutex, set done to
>> true and then notify the condition variable.
> Thank you for your explanation, Anthony.

You're welcome.

> As I am relatively new to threading, I have another question regarding
> your example:
>
> Are those variables considered to be for thread local storage. And if, would
> it be preferable then to use the 'extern' specifier in general?

Thread local storage is manifested in boost with
boost::thread_specific_ptr. It's use should be limited to globals (or
things that are effectively globals) where each thread must have its own
copy. Condition variables, mutexes and the "done" variable from this
example are used to communicate between threads, so must be accessible
to all threads concerned. Thread local storage is thus a bad idea.

The "extern" specifier was trying to convey the idea that these
variables are accessible from elsewhere. In general there is very little
reason to use extern in practice --- just declare you variables in a
shared header, for example.

> The problem for me (as a novice) on this example is, that it is shown in
> a very isolated context.

It was trying to demonstrate a specific feature (using timed wait for a
condition variable), not provide a full-featured example of condition
variable usage.

> When will the patches for the Sun Compiler be integrated into the trunk.
> For me, I use the CC 5.10 version, these patches worked well.

I will look over them today.

Anthony

-- 
Author of C++ Concurrency in Action | http://www.manning.com/williams
just::thread C++0x thread library   | http://www.stdthread.co.uk
Just Software Solutions Ltd         | http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net