just::thread Support Forum
General Category => General Discussion about just::thread => Topic started by: kjellkod on September 07, 2010, 02:38:04 PM
-
Hi,
I tried the deadlock detection sample in the documentation
I compiled as instructed
g++ -std=c++0x -pthread -D_JUST_THREAD_DEADLOCK_CHECK -g -rdynamic -o sample_deadlockcheck sample_deadlock.cpp -ljustthread -lrt
When running the program I do get the deadlock but I don't get the deadlock detection prinouts AND the app does not terminate (as it should with std::terminate), to make sure the standard error stream wasn't lost on me I called the sample like this
./sample_deadlockcheck &> log.out
I have not tested this on Windows yet, this was on Ubuntu
Best Regards
Kjell Hedström
-
Oops. The documentation needs updating. :(
You need to ensure that the just::thread headers are being used, and that the checked version of the library is being linked.
g++ -std=c++0x -pthread -I/usr/include/justthread -D_JUST_THREAD_DEADLOCK_CHECK -g -rdynamic -o sample_deadlockcheck sample_deadlock.cpp -ljustthread_check
If you don't link against the checked version of the library then you'll get linker errors if the include path is set up correctly.
Also, if you move the lock in main() to before the creation of the thread then you'll get a deadlock every time:
#include <thread>
#include <mutex>
#include <iostream>
std::mutex io_mutex;
void thread_func()
{
std::lock_guard<std::mutex> lk(io_mutex);
std::cout<<"Hello from thread_func"<<std::endl;
}
int main()
{
std::lock_guard<std::mutex> lk(io_mutex);
std::thread t(thread_func);
std::cout<<"Hello from main thread"<<std::endl;
t.join();
return 0;
}
-
I have updated the online documentation at http://www.stdthread.co.uk/doc/deadlockdebug.html (http://www.stdthread.co.uk/doc/deadlockdebug.html)
-
Thank you Anthony, that did it :D