Subject: [Boost-bugs] [Boost C++ Libraries] #1929: Borland/Codegear C++ 2007 creating boost::thread fails at initialisation of membervar boost::thread::thread_info
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-05-18 15:40:10
#1929: Borland/Codegear C++ 2007 creating boost::thread fails at initialisation of
membervar boost::thread::thread_info
-----------------------------------------------+----------------------------
Reporter: Giel van Schijndel <me_at_mortis.eu> | Type: Bugs
Status: new | Milestone: Boost 1.36.0
Component: None | Version: Boost 1.35.0
Severity: Problem | Keywords:
-----------------------------------------------+----------------------------
I'm attempting to create a thread in Borland/Codegear C++ 2007 (win32) by
means of code similar to this:
{{{
#!cpp
class Threaded
{
volatile bool _quit;
boost::thread _thread;
public:
Threaded() :
_quit(false),
_thread(boost::ref(*this))
{}
void operator()()
{
while (!_quit)
/* do stuff here */;
}
};
}}}
The results of several debugging sessions:
However as soon as the constructor of boost::thread gets invoked it will
call boost::thread::make_thread. This allocates some heap memory using the
Windows API and uses an in-place new to construct a detail::thread_data<T>
in that memory. The allocation and construction seem to work out very
well.
As soon as boost::thread::make_thread_info returns however it seems to
fail to assign the pointer to member variable thread_info in the
constructor.
I tried the below patch for debugging purposes, to see what happens.
Somehow the new variable (`tinfo`) remains NULL (all heap memory is
initialised to zero while debugging, hence the NULL) however. Thus it
seems that this compiler (borland) somehow fails to generate code that
properly assigns the pointer to boost::thread's member variables.
However, somehow assigning the value of `tinfo` to an on-stack variable
''does'' yield the correct pointer, while at the time the debugger says
that `tinfo` is still NULL, even though assigning it to another pointer
yields a non-NULL (and correct) value. So maybe it's pointer value is kept
in a register but only gets assigned to stack based variables but not to
member variables?
What's even more strange is that compiling a minimal test case ''outside''
of the IDE (using bjam) produces code that works. Unfortunately I cannot
use bjam for my project as it depends on Borland's VCL GUI library (if
it's possible to use bjam with Borland's VCL anyway please tell me where
to look/what to do, as up till now I've only failed miserably and have
little experience with bjam anyway).
Thus this ^^ leads me to believe that something differs in the compiler
options, I haven't got the slightest clue what it could be though. I've
got all optimisations turned off. Although I have no clue how to know what
command line options the IDE is calling the compiler with, so I cannot
compare it.
{{{
#!diff
Index: boost/thread/win32/thread.hpp
===================================================================
--- boost/thread/win32/thread.hpp (revision 45484)
+++ boost/thread/win32/thread.hpp (working copy)
@@ -196,6 +196,7 @@
};
mutable boost::mutex thread_info_mutex;
+ detail::thread_data_base* tinfo;
detail::thread_data_ptr thread_info;
static unsigned __stdcall thread_start_function(void* param);
@@ -214,7 +215,7 @@
}
#else
template<typename F>
- static inline detail::thread_data_ptr make_thread_info(F f)
+ static inline detail::thread_data_base* make_thread_info(F f)
{
return detail::heap_new<thread_data<F> >(f);
}
@@ -238,7 +239,8 @@
#else
template <class F>
explicit thread(F f):
- thread_info(make_thread_info(f))
+ tinfo(make_thread_info(f)),
+ thread_info(tinfo)
{
start_thread();
}
}}}
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1929>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC