Debugging threads with HP Wilde Beest
#define check_error(return_val, msg) { \
if (return_val != 0) \
fatal_error(return_val, msg); \
}
main()
{
pthread_t tid1;
extern void start_routine(int num);
int ret_val;
/*
* Create a thread
*/
ret_val = pthread_create(&tid1, (pthread_attr_t *)NULL,
(void *(*)())start_routine, (void *)1);
check_error(ret_val, "pthread_create 1 failed");
/*
* Wait for the threads to finish
*/
ret_val = pthread_join(tid1, (void **)NULL);
check_error(ret_val, "pthread_join: tid1");
}
void
start_routine(int thread_num)
{
int ret_val;
ret_val = pthread_mutex_unlock(&mtx);
check_error(ret_val, "mutex_unlock mtx");
}
This usually is indicative of error in the program logic. Typically, applications are coded
to lock and unlock objects on a one-one basis.
The following command enables you to detect this condition in a threaded application.
(gdb) set thread-check unlock_not_own on
The debugger transfers the execution control to the user and prints a warning message
when this condition is detected.
The following is a segment of the HP WDB output:
Starting program: /home/gdb/enh_thr_unlock_not_own
[Switching to thread 2 (system thread 39941)]
warning: Attempt to unlock mutex 1 not owned by thread 2.
0x800003ffeffcc608 in __rtc_pthread_dummy+0 () from ../librtc64.sl
Modes of Thread debugging in HP WDB 23