Debugging threads with HP Wilde Beest
if (return_val != 0) \
fatal_error(return_val, msg); \
}
main()
{
pthread_t tid;
int ret_val;
/* Create two threads to do the work */
ret_val = pthread_create(&tid, (pthread_attr_t *)NULL,
(void *(*)())producer_thread, (void *) &job_lock1);
check_error(ret_val, "pthread_create 2 failed");
/* Wait for the threads to finish */
ret_val = pthread_join(tid, (void **)NULL);
check_error(ret_val, "pthread_join: tid");
exit(0);
}
void
fatal_error(int err_num, char *function)
{
char *err_string;
err_string = strerror(err_num);
fprintf(stderr, "%s error: %s\n", function, err_string);
exit(-1);
}
The following command enables you to check this condition in a threaded application:
set thread-check thread-exit-own-mutex [on|off]
In such a scenario, the debugger transfers the execution control to the user and displays
a warning message.
The following is a segment of the HP WDB output:
Starting program: /home/gdb/enh_thr_exit_own_mx
[Switching to thread 2 (system thread 39677)]
warning: Attempt to exit thread 2 while holding a mutex 1.
0x800003ffeffcc608 in __rtc_pthread_dummy+0 () from ../librtc64.sl
30