Sourceware Bugzilla – Attachment 9338 Details for
Bug 20263
robust mutex deadlocks if other thread requests timedlock (Only arm/linux)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
robust mutex test code
a.c (text/plain), 2.70 KB, created by
Jiyoung Yun
on 2016-06-16 09:45:03 UTC
(
hide
)
Description:
robust mutex test code
Filename:
MIME Type:
Creator:
Jiyoung Yun
Created:
2016-06-16 09:45:03 UTC
Size:
2.70 KB
patch
obsolete
>#include <stdio.h> >#include <errno.h> >#include <assert.h> >#include <pthread.h> >#include <sys/types.h> >#include <sys/syscall.h> > >#define PRT(fmt, arg...) printf("[%d] (%d) "fmt"\n", syscall(SYS_gettid), __LINE__, ##arg) > >pthread_mutex_t mutex; >pthread_mutex_t pp = PTHREAD_MUTEX_INITIALIZER; > >void *child(void *arg) >{ > int ret; > > PRT("Start Child..."); > > PRT("Lock Mutex"); > ret = pthread_mutex_lock(&mutex); > if (ret == 0) > PRT("Acquire Mutex"); > else > PRT("ERR : %d", ret); > > sleep(1); > do { > PRT("Trylock..."); > ret = pthread_mutex_trylock(&pp); > if (ret == 0) { > PRT("Trylock... Lock!!!"); > break; > } > sleep(1); > } while(1); > > PRT("Unlock pp Mutex"); > ret = pthread_mutex_unlock(&pp); > if (ret != 0) > PRT("ERR : %d", ret); > > PRT("End Child"); >} > >void *parent(void *arg) >{ > int ret; > struct timespec abstime; > > PRT("Start Parent..."); > > PRT("Lock pp Mutex"); > ret = pthread_mutex_lock(&pp); > if (ret == 0) > PRT("Acquire pp Mutex"); > else > PRT("ERR : %d", ret); > > sleep(1); > do { > clock_gettime(CLOCK_REALTIME, &abstime); > abstime.tv_sec += 10; > PRT("Timedlock..."); > ret = pthread_mutex_timedlock(&mutex, &abstime); > PRT("ret : %d", ret); > if (ret == ETIMEDOUT) { > PRT("Timedlock... ETIMEDOUT"); > break; > } > ret = pthread_mutex_unlock(&mutex); > if (ret != 0) > PRT("ERR : %d", ret); > sleep(1); > } while(1); > > PRT("Unlock pp Mutex"); > ret = pthread_mutex_unlock(&pp); > if (ret != 0) > PRT("ERR : %d", ret); > > PRT("End Parent"); >} > >int main(int argc, char *argv[]) >{ > pthread_t tid0, tid1; > pthread_mutexattr_t mutexAttributes; > int ret; > > PRT("Init Mutex Attribute"); > ret = pthread_mutexattr_init(&mutexAttributes); > assert(ret == 0); > > ret = pthread_mutexattr_setpshared(&mutexAttributes, PTHREAD_PROCESS_SHARED); > assert(ret == 0); > > ret = pthread_mutexattr_setrobust(&mutexAttributes, PTHREAD_MUTEX_ROBUST); > assert(ret == 0); > >// ret = pthread_mutexattr_settype(&mutexAttributes, PTHREAD_MUTEX_RECURSIVE); >// assert(ret == 0); > ret = pthread_mutexattr_settype(&mutexAttributes, PTHREAD_MUTEX_ERRORCHECK); > assert(ret == 0); > > PRT("Init Mutex"); > ret = pthread_mutex_init(&mutex, &mutexAttributes); > > ret = pthread_mutexattr_destroy(&mutexAttributes); > assert(ret == 0); > > pthread_create(&tid0, NULL, child, NULL); > pthread_create(&tid1, NULL, parent, NULL); > > pthread_join(tid0, NULL); > pthread_join(tid1, NULL); > > ret = pthread_mutex_destroy(&mutex); > assert(ret == 0 || ret == EBUSY); > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 20263
: 9338 |
9365
|
9366