|
From: Joshua Moore-O. <jo...@ch...> - 2004-06-03 23:45:20
|
When running a multi-threaded C++ program with valgrind, I get the following output... Thread 2: ==26867== Conditional jump or move depends on uninitialised value(s) ==26867== at 0x3C531FC1: (within /usr/lib/valgrind/libpthread.so) ==26867== by 0xB800FAB4: (within /usr/lib/valgrind/stage2) ==26867== ==26867== Thread 2: ==26867== thread_wrapper: invalid attr->__detachstate ==26867== at 0x3C530FDF: (within /usr/lib/valgrind/libpthread.so) ==26867== by 0x3C531FD0: (within /usr/lib/valgrind/libpthread.so) ==26867== by 0xB800FAB4: (within /usr/lib/valgrind/stage2) ==26867== ==26867== Thread 2: ==26867== Conditional jump or move depends on uninitialised value(s) ==26867== at 0x3C531FD4: (within /usr/lib/valgrind/libpthread.so) ==26867== by 0xB800FAB4: (within /usr/lib/valgrind/stage2) I have two threads, one is my main, and the other a created thread. This appears to occur in the thread startup routine, e.g. in the new created thread after it was launched by main. Now what's really weird, is that my main thread is looping through usleep(500000); waiting for the launched thread to finish. Once it is finished, my main thread silently exits never getting out of the usleep, with no complaint whatsoever from valgrind. When I run my program without valgrind, my program exists normally, and all the above information leads me to think that there is something wrong with the valgrind pthread emulation library... But if it's not the library, what could I possibly be doing to create this kind of behaviour? Thanks, Joshua Moore-Oliva |
|
From: Joshua Moore-O. <jo...@ch...> - 2004-06-03 23:53:59
|
So I did some more debugging and this is the difference in execution...
It appears that after a pthread_create, valgrind is
***executing to the end of the function after a pthread_create call for BOTH the caller and the new thread***
This behaviour only exhibits itself while using valgrind.
Here is the two functions this output is going through
template <class __LOGIC_EXCEPT
, class __RUNTIME_EXCEPT>
void Thread<__LOGIC_EXCEPT
, __RUNTIME_EXCEPT>::launch( ) {
pthread_t ptId;
pthread_attr_t ptaAttr;
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
if ( pthread_attr_init( &ptaAttr ) != 0 ) {
throw __RUNTIME_EXCEPT( STRING_LOG_INFO
+ "Error in pthread_attr_init. " + strerror(errno) + "." );
}
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
if ( pthread_attr_setdetachstate( &ptaAttr, PTHREAD_CREATE_DETACHED ) != 0 ) {
throw __RUNTIME_EXCEPT( STRING_LOG_INFO
+ "Error in pthread_attr_setdetachstate. " + strerror(errno) + "." );
}
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
if ( pthread_create( &ptId
, &ptaAttr
, Thread::threadLaunch
, this ) != 0 ) {
throw __RUNTIME_EXCEPT( STRING_LOG_INFO
+ "Error in pthread_create. " + strerror(errno) + "." );
}
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
}
template <class __LOGIC_EXCEPT
, class __RUNTIME_EXCEPT>
void * Thread<__LOGIC_EXCEPT
, __RUNTIME_EXCEPT>::threadLaunch( void * vArg ) {
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
Thread * oThread = (Thread *)vArg;
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
pthread_cleanup_push( Thread::threadDestroy, oThread );
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
oThread->run();
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
pthread_cleanup_pop( 1 );
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
pthread_exit( NULL );
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
}
pthread_t ptId;
pthread_attr_t ptaAttr;
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
if ( pthread_attr_init( &ptaAttr ) != 0 ) {
throw __RUNTIME_EXCEPT( STRING_LOG_INFO
+ "Error in pthread_attr_init. " + strerror(errno) + "." );
}
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
if ( pthread_attr_setdetachstate( &ptaAttr, PTHREAD_CREATE_DETACHED ) != 0 ) {
throw __RUNTIME_EXCEPT( STRING_LOG_INFO
+ "Error in pthread_attr_setdetachstate. " + strerror(errno) + "." );
}
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
if ( pthread_create( &ptId
, &ptaAttr
, Thread::threadLaunch
, this ) != 0 ) {
throw __RUNTIME_EXCEPT( STRING_LOG_INFO
+ "Error in pthread_create. " + strerror(errno) + "." );
}
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
Here is the relevant output for valgrind
/home/chatgris/code/cpp/Thread/launch.cpp:11
/home/chatgris/code/cpp/Thread/launch.cpp:18
/home/chatgris/code/cpp/Thread/launch.cpp:25
/home/chatgris/code/cpp/Thread/launch.cpp:35
==27000== Thread 2:
==27000== Conditional jump or move depends on uninitialised value(s)
==27000== at 0x3C531FC1: (within /usr/lib/valgrind/libpthread.so)
==27000== by 0xB800FAB4: (within /usr/lib/valgrind/stage2)
==27000==
==27000== Thread 2:
==27000== thread_wrapper: invalid attr->__detachstate
==27000== at 0x3C530FDF: (within /usr/lib/valgrind/libpthread.so)
==27000== by 0x3C531FD0: (within /usr/lib/valgrind/libpthread.so)
==27000== by 0xB800FAB4: (within /usr/lib/valgrind/stage2)
==27000==
==27000== Thread 2:
==27000== Conditional jump or move depends on uninitialised value(s)
==27000== at 0x3C531FD4: (within /usr/lib/valgrind/libpthread.so)
==27000== by 0xB800FAB4: (within /usr/lib/valgrind/stage2)
ResolveManager[27000]: Main/go.cpp: Main: Threads Launched.
ResolveManager[27000]: Main/go.cpp: Main: Waiting on signals.
/home/chatgris/code/cpp/Thread/launch.cpp:35
/home/chatgris/code/cpp/Thread/threadLaunch.cpp:8
/home/chatgris/code/cpp/Thread/threadLaunch.cpp:12
/home/chatgris/code/cpp/Thread/threadLaunch.cpp:16
Here is the relevant output without valgrind
/home/chatgris/code/cpp/Thread/launch.cpp:11
/home/chatgris/code/cpp/Thread/launch.cpp:18
/home/chatgris/code/cpp/Thread/launch.cpp:25
/home/chatgris/code/cpp/Thread/launch.cpp:35
ResolveManager[27016]: Main/go.cpp: Main: Threads Launched.
ResolveManager[27016]: Main/go.cpp: Main: Waiting on signals.
/home/chatgris/code/cpp/Thread/threadLaunch.cpp:8
/home/chatgris/code/cpp/Thread/threadLaunch.cpp:12
/home/chatgris/code/cpp/Thread/threadLaunch.cpp:16
Joshua Moore-Oliva
|