FreeBSD Bugzilla – Attachment 169973 Details for
Bug 209233
[patch] pthread_suspend_all_np races with check_suspend
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
test case
file_209233.txt (text/plain), 1.30 KB, created by
Lawrence Esswood
on 2016-05-04 17:57:50 UTC
(
hide
)
Description:
test case
Filename:
MIME Type:
Creator:
Lawrence Esswood
Created:
2016-05-04 17:57:50 UTC
Size:
1.30 KB
patch
obsolete
>#include <stdio.h> >#include <pthread.h> >#include <pthread_np.h> >#include <unistd.h> >#include <stdlib.h> > >volatile int flag = 0; >int n = 100; > >void busyLoop() { > volatile int ctr; > for(int i = 0; i < 1000000; i++) ctr++; >} > >void* check_flags(void* x) { > > pthread_suspend_all_np(); > if(flag != 0) { > printf("Should have got mutual exclusion\n"); > exit(1); > } > flag = 1; > busyLoop(); > flag = 0; > pthread_resume_all_np(); > return 0; >} > >int test() { > pthread_t threads[n]; > for(int i = 0; i < n; i++) { > int ret = pthread_create(&threads[i], NULL, check_flags, NULL); > if(ret != 0) { > printf("Creation fail %d\n", ret); > return ret; > } > } > for(int i = 0; i < n; i++) { > int ret = pthread_join(threads[i], NULL); > if(ret != 0) { > printf("Join fail %d\n", ret); > return ret; > } > } > > return 0; >} > >int main(void) { > for(int i = 0; i < 100; i++) { > int ret = test(); > if(ret != 0) return ret; > } > 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 209233
:
169926
|
169969
|
169971
| 169973