Sourceware Bugzilla – Attachment 11450 Details for
Bug 23844
pthread_rwlock_trywrlock results in hang
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
test case for tryrdlock hangs
bug23844.rd.c (text/x-csrc), 2.63 KB, created by
Rik Prohaska
on 2018-12-11 15:57:11 UTC
(
hide
)
Description:
test case for tryrdlock hangs
Filename:
MIME Type:
Creator:
Rik Prohaska
Created:
2018-12-11 15:57:11 UTC
Size:
2.63 KB
patch
obsolete
>/* > Test case for pthread hang using pthread_rwlock_trywrlock > Hangs if TRYLOCK_WR is set. >*/ > >#include <stdlib.h> >#include <stdio.h> >#include <pthread.h> >#include <errno.h> > >#define NLOCK 1 >#define NTHREAD 32 > >#define TRYLOCK_WR 0 >#define TRYLOCK_RD 1 > >pthread_rwlock_t rw_lock[NLOCK]; >int var[NLOCK]; > >void *runner(void *arg) >{ > int i; > > for(i = 0; i < 1000000; i++) > { > int ecode, idx, rw; > > idx = i % NLOCK; > rw = (i & (16|8)) == (16|8); > > if(rw) { >#if TRYLOCK_WR > if((ecode = pthread_rwlock_trywrlock(&rw_lock[idx]))) { > if(ecode == EBUSY) > ecode = pthread_rwlock_wrlock(&rw_lock[idx]); > if(ecode) { > perror("pthread_rwlock_wrlock"); > exit(1); > } > } >#else > if((ecode = pthread_rwlock_wrlock(&rw_lock[idx]))) { > perror("pthread_rwlock_wrlock"); > exit(1); > } >#endif > } > else { >#if TRYLOCK_RD > if((ecode = pthread_rwlock_tryrdlock(&rw_lock[idx]))) { > if(ecode == EBUSY) > ecode = pthread_rwlock_rdlock(&rw_lock[idx]); > if(ecode) { > perror("pthread_rwlock_rdlock"); > exit(1); > } > } >#else > if((ecode = pthread_rwlock_rdlock(&rw_lock[idx]))) { > perror("pthread_rwlock_rdlock"); > exit(1); > } >#endif > } > > if(rw) > var[i % NLOCK] += 1; > > if((ecode = pthread_rwlock_unlock(&rw_lock[idx]))) { > perror("pthread_rwlock_unlock"); > exit(1); > } > } > > pthread_exit(NULL); >} > >int main(int argc, char **argv) >{ > pthread_rwlockattr_t rw_attr; > int i, ecode; > pthread_t t_list[NTHREAD]; > > int nthread = 2; > if(argc > 1) > nthread = atoi(argv[1]); > if(nthread > NTHREAD) > nthread = NTHREAD; > >#if TRYLOCK_WR > printf("trylock_wr\n"); >#endif >#if TRYLOCK_RD > printf("trylock_rd\n"); >#endif > > pthread_rwlockattr_init(&rw_attr); > > for(i = 0; i < NLOCK; i++) > if((ecode = pthread_rwlock_init(&rw_lock[i], &rw_attr))) { > perror("pthread_rwlock_init"); > exit(1); > } > > for(i = 0; i < nthread; i++) > if((ecode = pthread_create(&t_list[i], NULL, runner, NULL))) { > perror("pthread_create"); > exit(1); > } > > for(i = 0; i < nthread; i++) > if((ecode = pthread_join(t_list[i], NULL))) { > perror("pthread_join"); > exit(1); > } > > for(i = 0; i < NLOCK; i++) > if((ecode = pthread_rwlock_destroy(&rw_lock[i]))) { > perror("pthread_rwlock_destroy"); > exit(1); > } > > for(i = 0; i < NLOCK; i++) > printf("%d\n", var[i]); > > 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 23844
:
11373
|
11448
|
11449
| 11450 |
11457