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-28 10:53:40


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

> The code sample I used is from the boost documentation of
> the thread's library at:
>
> http://www.boost.org/doc/libs/1_39_0/doc/html/thread/time.html
>
> Here's the code:
>
> int main(int argc, char** argv) {
>
> boost::system_time const timeout = boost::get_system_time() +
> boost::posix_time::milliseconds(500);
>
> extern bool done = true;
> extern boost::mutex m;
> extern boost::condition_variable cond;
>
> boost::unique_lock<boost::mutex> lk(m);
> while (!done)
> {
> if (!cond.timed_wait(lk, timeout))
> {
> throw "timed out";
> }
> }
>
> return (EXIT_SUCCESS);
> }
>
> But as with the code provided on the net (see link above) where
> the variables (done, m, cond) are specified with extern, the linker
> always moaned that it couldn't resolve those symbols. So IMHO this
> example is not well suited for a standalone example.

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.

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