Last change
on this file since 6cb3e5d was d923fca, checked in by Andrew Beach <ajbeach@…>, 7 months ago |
Clean-up the warnings of the concurrency tests. A lot of little test level fixes, the most interesting repeated one is some formally redundent fallthough statements. pthread_attr_test had to be rewritten because of library restrictions. Changed some types so they would always be pointer sized. There was a library change, there was a function that could not be implemented; I trust that it is included for a reason so I just put it in a comment. There is a change to the compiler, wait-until now uses goto. The labelled breaks were code generated as unlabelled breaks and although it worked out slipped through some checks. Finally, there is one warning that I cannot solve at this time so tests that produce it have been put in their own lax group.
|
-
Property mode
set to
100644
|
File size:
856 bytes
|
Line | |
---|
1 | #include <fstream.hfa>
|
---|
2 | #include <thread.hfa>
|
---|
3 | /* test pthread create/join/exit */
|
---|
4 |
|
---|
5 | size_t arr[20];
|
---|
6 |
|
---|
7 | void* fetch(void* idx){
|
---|
8 | size_t res = arr[(size_t)idx];
|
---|
9 | pthread_exit((void*)res);
|
---|
10 | sout | "it should not be here";
|
---|
11 | exit(1);
|
---|
12 | //return (void*)res;
|
---|
13 | }
|
---|
14 |
|
---|
15 | void arr_init(){
|
---|
16 | for (int i = 0; i < 20; i++){
|
---|
17 | arr[i] = i;
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | int main()
|
---|
22 | {
|
---|
23 | pthread_t threads[20];
|
---|
24 | arr_init();
|
---|
25 | int status;
|
---|
26 | for (size_t i = 0; i < 20; i++){
|
---|
27 | status = pthread_create(&threads[i], NULL, fetch, (void*)i);
|
---|
28 | if (status != 0) exit(1);
|
---|
29 | }
|
---|
30 | int res = 0;
|
---|
31 | for (int i = 0; i < 20; i++){
|
---|
32 | void* res_i = NULL;
|
---|
33 | status = pthread_join(threads[i], &res_i);
|
---|
34 | if (status != 0) exit(2);
|
---|
35 | if (((size_t)res_i) != i) exit(3);
|
---|
36 | res += (size_t)res_i;
|
---|
37 | }
|
---|
38 | sout | "final res is" | res;
|
---|
39 |
|
---|
40 | return 0;
|
---|
41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.