source: tests/concurrency/pthread/pthread_demo_create_join.cfa@ e1358c0

Last change on this file since e1358c0 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
RevLine 
[20be782]1#include <fstream.hfa>
2#include <thread.hfa>
[428adbc]3/* test pthread create/join/exit */
4
[d923fca]5size_t arr[20];
[20be782]6
7void* fetch(void* idx){
[d923fca]8 size_t res = arr[(size_t)idx];
[20be782]9 pthread_exit((void*)res);
10 sout | "it should not be here";
11 exit(1);
12 //return (void*)res;
13}
14
15void arr_init(){
16 for (int i = 0; i < 20; i++){
17 arr[i] = i;
18 }
19}
20
[d923fca]21int main()
[20be782]22{
23 pthread_t threads[20];
24 arr_init();
25 int status;
[d923fca]26 for (size_t i = 0; i < 20; i++){
[20be782]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++){
[d923fca]32 void* res_i = NULL;
33 status = pthread_join(threads[i], &res_i);
[20be782]34 if (status != 0) exit(2);
[d923fca]35 if (((size_t)res_i) != i) exit(3);
36 res += (size_t)res_i;
[20be782]37 }
38 sout | "final res is" | res;
39
40 return 0;
41}
Note: See TracBrowser for help on using the repository browser.