How to restrict gdb debugging to one thread at a time

As TazMainiac said, scheduler-locking is useful for single stepping, but the “mode” must be set to “step”. set scheduler-locking step You can refer the link provided by TazMainiac which mentions the same: http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_node/gdb_39.html The step mode optimizes for single-stepping. It stops other threads from “seizing the prompt” by preempting the current thread while you are … Read more

Advantages of using condition variables over mutex

A condition variable allows a thread to be signaled when something of interest to that thread occurs. By itself, a mutex doesn’t do this. If you just need mutual exclusion, then condition variables don’t do anything for you. However, if you need to know when something happens, then condition variables can help. For example, if … Read more

pthread_exit vs. return

The following minimal test case exhibits the behaviour you describe: #include <pthread.h> #include <unistd.h> void *app1(void *x) { sleep(1); pthread_exit(0); } int main() { pthread_t t1; pthread_create(&t1, NULL, app1, NULL); pthread_join(t1, NULL); return 0; } valgrind –leak-check=full –show-reachable=yes shows 5 blocks allocated from functions called by pthread_exit() that is unfreed but still reachable at process … Read more

Kill Thread in Pthread Library

First store the thread id pthread_create(&thr, …) then later call pthread_cancel(thr) However, this not a recommended programming practice! It’s better to use an inter-thread communication mechanism like semaphores or messages to communicate to the thread that it should stop execution. Note that pthread_kill(…) does not actually terminate the receiving thread, but instead delivers a signal … Read more