Board index » cppbuilder » Boost users please confirm (compiler bug?)

Boost users please confirm (compiler bug?)


2007-11-26 10:50:56 PM
cppbuilder34
Can anybody using boost 1.34 (or lower) with BCB2006(2007?)
confirm this error?
Uncommenting line B in the posted example triggers Access
violation exception when the program is run. When run in IDE the
de{*word*81} stops in mutex::do_unlock(). See caller stack and other
context bellow.
This is strange as the function thr() containing that line
does not get called anywhere in the example. Only the fact that
it has been compiled triggers a runtime error.
Setup:
- boost 1.34.1 with bcbboost
- Mulithreaded console application without VCL
- Static linking with 'LIBBOOST_THREAD-BCB-MT-SD-1_34_1.LIB'
(BOOST_THREAD_USE_LIB defined)
- RTL static linking
The AV exception is thrown from boost's thread constructor:
thread::thread() calls thread_param::wait() and it creates a
scoped_lock object that upon destruction calls do_unlock upon
a thread_param internal mutex that got strangely NULL.
caller stack:
:7c812a5b kernel32.RaiseException + 0x52
:0041271a ___raiseDe{*word*81}Exception + 0x1A
:004127f4 ; ___raiseDe{*word*81}Exception
:7c9037bf ntdll.RtlConvertUlongToLargeInteger + 0x7a
:7c90378b ntdll.RtlConvertUlongToLargeInteger + 0x46
:7c90eafa ntdll.KiUserExceptionDispatcher + 0xe
:0041F5A7 boost::mutex::do_unlock(this=NULL, =:0012FDE0)
:0041DFC6 boost::detail::thread::lock_ops<boost::mutex>::unlock(m=NULL, state=:0012FDE0)
:0041DD51 boost::condition::do_wait<boost::mutex>(this=:0012FE9C, mutex=NULL)
:0041DA52 boost::condition::wait<boost::detail::thread::scoped_lock<boost::mutex>>(this=:0012FE9C, lock=:0012FE54)
:0041D19F __UNNS__thread_01c827c2c2c9169a::thread_param::wait(this=:0012FE94)
:0041D001 boost::thread::thread(this=:00000FCC, threadfunc=:00000FC8)
:0012fe01
//---------------------------------------------------------------------------
#include <iostream>
#include <boost/thread.hpp>
#include <memory>
//---------------------------------------------------------------------------
boost::mutex *console = 0; // line A
void thr() // int n, boost::mutex & display
{
if (console == 0)
return;
for (int i = 0; i < 10; i++)
{
//boost::mutex::scoped_lock l(*console); // line B
std::cout << "thr" << 1 << ":" << i << std::endl;
} // end for
}
void dummy_thr() // int n, boost::mutex & display
{
}
int main(int argc, char* argv[])
{
boost::thread_group tg;
std::auto_ptr<boost::mutex>(console = new boost::mutex);
tg.create_thread(&dummy_thr);
char c;
std::cin>>c ;
return 0;
}
//---------------------------------------------------------------------------
 
 

Re:Boost users please confirm (compiler bug?)

"Vaclav Cechura" < XXXX@XXXXX.COM >wrote:
Quote
The AV exception is thrown from boost's thread constructor:
thread::thread() calls thread_param::wait() and it creates a
scoped_lock object that upon destruction calls do_unlock upon
a thread_param internal mutex that got strangely NULL.
This is not true now.
I slightly simplified the example during the writing of this
post and forgot to recheck. The error is now raised in other
part of the boost code (see the caller stack).
Vaclav
 

Re:Boost users please confirm (compiler bug?)

Hi.
I recall having AVs in "boost" because of different compiler options in my
projects and the "boost"-libraries. Check the compiler options of your
project(s) and compare them to the compile options in the boost-jamfile
('borland-tools.jam').
Regards
Eike Petersen
Vaclav Cechura wrote:
Quote
Can anybody using boost 1.34 (or lower) with BCB2006(2007?)
confirm this error?

Uncommenting line B in the posted example triggers Access
violation exception when the program is run. When run in IDE the
de{*word*81} stops in mutex::do_unlock(). See caller stack and other
context bellow.

This is strange as the function thr() containing that line
does not get called anywhere in the example. Only the fact that
it has been compiled triggers a runtime error.

Setup:
- boost 1.34.1 with bcbboost
- Mulithreaded console application without VCL
- Static linking with 'LIBBOOST_THREAD-BCB-MT-SD-1_34_1.LIB'
(BOOST_THREAD_USE_LIB defined)
- RTL static linking

 

{smallsort}

Re:Boost users please confirm (compiler bug?)

Eike Petersen < XXXX@XXXXX.COM >wrote:
Quote
I recall having AVs in "boost" because of different compiler options in my
projects and the "boost"-libraries. Check the compiler options of your
project(s) and compare them to the compile options in the boost-jamfile
('borland-tools.jam').
Thank you for the tip.
The file seems now to be called 'borland.jam'.
I found a difference in -Ve and -Vx settings which borland.jam
considers to be default settings in IDE, which is not true for
BCB2006 (project multithreaded console application without VCL).
Setting -Ve -Vx made the AV exception disappear for the example
in the original post. Strangely an AV exception reappeared when
I modified the code to allocate mutex 'console' using new in
main().
This still gives AV exception:
boost::mutex *console = 0; // line A
void thr()
{
if (console == 0)
return;
for (int i = 0; i < 10; i++)
{
boost::mutex::scoped_lock l(*console); // line B
std::cout << "thr" << 1 << ":" << i << std::endl;
} // end for
}
void dummy_thr() // int n, boost::mutex & display
{
}
int main(int argc, char* argv[])
{
boost::thread_group tg;
std::auto_ptr<boost::mutex>(console = new boost::mutex());
tg.create_thread(&thr);
tg.join_all();
char c;
std::cin>>c ;
return 0;
}
After the AV exception de{*word*81} stops at the line 'm.do_lock()'
in lock.hpp:
template <typename Mutex>
class lock_ops : private noncopyable
{
private:
lock_ops() { }
public:
typedef typename Mutex::cv_state lock_state;
static void lock(Mutex& m)
{
m.do_lock(); //////// de{*word*81} stops here
}
On the other hand I can compile and run this code withou an AV:
boost::mutex console; // line A
void thr(std::ostream & sout, int n, boost::mutex &console) // int n, boost::mutex & display
{
for (int i = 0; i < 10; i++)
{
boost::mutex::scoped_lock l(console); // line B
sout << "thr_" << n << "_" << i << ' '; // std::endl;
} // end for
}
void dummy_thr()
{
}
int main(int argc, char* argv[])
{
boost::thread_group tg;
for(int i = 0; i < 10; i++)
{
tg.create_thread(boost::bind(thr,boost::ref(std::cout),i+1,boost::ref(console)));
}
tg.join_all();
char c;
std::cin>>c ;
return 0;
}
 

Re:Boost users please confirm (compiler bug?)

I think you made a mistake where you try to use the auto_ptr.
Quote
std::auto_ptr<boost::mutex>(console = new boost::mutex());
This line does not do, what you intended it to do. In fact it constructs an
unnamed auto_ptr which gets immediately destroyed and deletes your newly
constructed mutex directly after construction.
This should do it:
std::auto_ptr<boost::mutex>ap(console = new boost::mutex());
Regards
Eike Petersen
Vaclav Cechura wrote:
Quote
This still gives AV exception:

boost::mutex *console = 0; // line A

void thr()
{
if (console == 0)
return;

for (int i = 0; i < 10; i++)
{
boost::mutex::scoped_lock l(*console); // line B
std::cout << "thr" << 1 << ":" << i << std::endl;
} // end for
}

void dummy_thr() // int n, boost::mutex & display
{
}

int main(int argc, char* argv[])
{
boost::thread_group tg;

std::auto_ptr<boost::mutex>(console = new boost::mutex());

tg.create_thread(&thr);

tg.join_all();

char c;
std::cin>>c ;
return 0;
}