Boost logo

Boost :

Subject: Re: [boost] [thread] 1.41.0 regression
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2009-12-16 03:09:54

Dmitry Goncharov <dgoncharov_at_[hidden]> writes:

> The thread_data_base constructor is defined in a header file. Function
> make_external_thread_data() is defined in a .cpp file. This can lead
> to a situation when different libraries contain the definitions of
> these functions. The example below explains how this can happen and
> why this causes problems.

It always causes problems if your program has two incompatible
definitions of the same structure. It's a violation of the One
Definition Rule.

> There is a library (e.g. which uses the Boost.Thread
> library. Since the thread_data_base constructor is defined in a header
> file can contain its definition.
> Again, the size of thread_data_base object, that the thread_data_base
> constructor from expects, depends on if was
> built with _GLIBCXX_DEBUG defined or not.
> An application cannot link agains both and
> if these libraries were built with different _GLIBCXX_DEBUG
> definitions (or different alignment, etc).
> While loading the application the dynamic linker will use the
> definition of thread_data_base constructor either from be
> or from Whichever it finds first.
> Can both the thread_data_base constructor and
> make_external_thread_data() reside either in a .cpp file or in a
> header?

That won't make any difference. All the thread structures that are
defined in header files must have the same layout in the app as in the
thread library, otherwise you will either get linker errors or (worse)
runtime errors due to incorrect structure offsets.

The solution is to use the same compiler flags when you build your
application as when you build the boost thread library, to ensure that
the structures have the same layout.


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 list run by bdawes at, gregod at, cpdaniel at, john at