pthread_attr_setschedpolicy/2-1.c: fix race at thread startup
Test can hang during startup in following scenario:
main new thread
--------------------------------------------------+-------------------------------------
int create_thread(int prio, pthread_t * tid) |
... |
pthread_create(tid, &attr, thread_func, NULL);|
while (!thread_started) { |
| void *thread_func(void *data)
| thread_started = 1;
| pthread_cond_signal(&cond);
pthread_mutex_lock(&c_mutex); |
132: pthread_cond_wait(&cond, &c_mutex); |
|65: pthread_mutex_lock(&mutex);
|
(gdb) bt
#0 0x00007fd588808f6d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007fd588804d31 in _L_lock_790 () from /lib64/libpthread.so.0
#2 0x00007fd588804c37 in pthread_mutex_lock () from /lib64/libpthread.so.0
#3 0x0000000000400bba in thread_func (data=0x0) at ../../../conformance/interfaces/pthread_attr_setschedpolicy/2-1.c:65
#4 0x00007fd588802de3 in start_thread () from /lib64/libpthread.so.0
#5 0x00007fd5885300dd in clone () from /lib64/libc.so.6
(gdb) t 2
(gdb) bt
#0 0x00007fd5888066f5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x0000000000400d9b in create_thread (prio=5, tid=0x7fffdb562678) at ../../../conformance/interfaces/pthread_attr_setschedpolicy/2-1.c:132
#2 0x0000000000400e82 in main () at ../../../conformance/interfaces/pthread_attr_setschedpolicy/2-1.c:174
Fix this by using same c_mutex in thread_func for updating
thread_started and signalling cond.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
1 file changed