Product SiteDocumentation Site

4.6. Debugging with libtcr

One needs to keep in mind, that gdb's thread support will only see libtcr's worker threads, usually the same number of threads as CPUs are in the system. Tc_threads are not directly seen by gdb. The libtcr framework brings three configure options to aid debugging.
The optimized version of a spinlock contains only a single machine word, in which only a single bit is actually used.
With this configure option, the debug version of spinlocks is enabled. In debug mode each spinlock has a reference to the current holder (tc_thread name, source code file name and line number). If trying to lock a spinlock takes longer than 4 million iterations[5] of the busy-wait loop, it will terminate the program, and output where acquiring the lock took too long, and which tc_thread currently holds the lock, and where it got it.
Normally a new tc_thread's stack gets allocated by malloc(3), by default 16KiByte. Failures of setting a possibly required greater stack size using tc_set_stack_size(3) lead to programs failing in mystical ways.
With this configure option set, each stack area is allocated by mmap(2) and the neighboring page is mapped as non-accessible, with that stack overruns are detected where they happen.
With this configure option set, each sleeping tc_thread has a reference to the line in the program where a blocking tc_ function call was made that caused it to sleep.
In an appropriate place, the application should have a call to the tc_dump_threads() function which will output the current location of all blocked tc_threads. E.g. in the signal handler of SIGUSR1.
If the program blocks, and a deadlock and the suspicion is that a deadlock is the cause for it, the signal can be used to find out where all the tc_threads are waiting.


If you are going to package libtcr for a distribution, please also provide header files and a library with debugging enabled, with the development resources of the library.

[5] That takes only a fraction of a second on a workstation bought in the Year 2009.