- Timestamp:
- Feb 18, 2025, 12:54:23 PM (6 weeks ago)
- Branches:
- master
- Children:
- 8705a11
- Parents:
- 3e5fea2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified tests/concurrency/pthread/pthread_demo_create_join.cfa ¶
r3e5fea2 rd923fca 3 3 /* test pthread create/join/exit */ 4 4 5 int arr[20];5 size_t arr[20]; 6 6 7 7 void* fetch(void* idx){ 8 int res = arr[(uint64_t)idx];8 size_t res = arr[(size_t)idx]; 9 9 pthread_exit((void*)res); 10 10 sout | "it should not be here"; … … 19 19 } 20 20 21 int main( int argc, char const *argv[])21 int main() 22 22 { 23 23 pthread_t threads[20]; 24 24 arr_init(); 25 25 int status; 26 for ( int i = 0; i < 20; i++){26 for (size_t i = 0; i < 20; i++){ 27 27 status = pthread_create(&threads[i], NULL, fetch, (void*)i); 28 28 if (status != 0) exit(1); … … 30 30 int res = 0; 31 31 for (int i = 0; i < 20; i++){ 32 void* _res= NULL;33 status = pthread_join(threads[i], & _res);32 void* res_i = NULL; 33 status = pthread_join(threads[i], &res_i); 34 34 if (status != 0) exit(2); 35 if ((( uint64_t)_res) != i) exit(3);36 res += ( uint64_t)_res;35 if (((size_t)res_i) != i) exit(3); 36 res += (size_t)res_i; 37 37 } 38 38 sout | "final res is" | res;
Note: See TracChangeset
for help on using the changeset viewer.