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:
> 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.


Author of C++ Concurrency in Action |
just::thread C++0x thread library   |
Just Software Solutions Ltd         |
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at