Changeset d923fca for tests/concurrency/pthread
- Timestamp:
- Feb 18, 2025, 12:54:23 PM (7 months ago)
- Branches:
- master
- Children:
- 8705a11
- Parents:
- 3e5fea2
- Location:
- tests/concurrency/pthread
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/pthread/pthread_attr_test.cfa
r3e5fea2 rd923fca 4 4 #include <thread.hfa> 5 5 6 void* foo(void* _attr){ 6 void* foo(void*){ 7 pthread_t self = pthread_self(); 8 pthread_attr_t self_attr; 9 pthread_getattr_np(self, &self_attr); 10 7 11 size_t size; 8 pthread_attr_t* attr = (pthread_attr_t*)_attr; 9 int status = pthread_attr_getstacksize(attr, &size); 12 int status = pthread_attr_getstacksize(&self_attr, &size); 10 13 if (status != 0){ 11 14 sout | "error return code"; … … 16 19 } 17 20 18 int main( int argc, char const *argv[])21 int main() 19 22 { 20 23 pthread_attr_t attr; … … 23 26 pthread_t thr; 24 27 void* res; 25 pthread_create(&thr, &attr, foo, (void*) &attr);28 pthread_create(&thr, &attr, foo, (void*)0); 26 29 pthread_join(thr, &res); 27 30 pthread_attr_destroy(&attr); -
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; -
tests/concurrency/pthread/pthread_key_test.cfa
r3e5fea2 rd923fca 16 16 #define BUFFSZ 48 17 17 pthread_key_t key; 18 volatile int total_value,total_value_getspec; 18 volatile size_t total_value; 19 volatile size_t total_value_getspec; 19 20 pthread_mutex_t value_mutex; 20 21 … … 26 27 int *tnum; 27 28 void *getvalue; 28 char Buffer[BUFFSZ];29 29 30 30 tnum = (int*)parm; … … 32 32 33 33 //printf("Thread %d executing\n", threadnum); 34 value = (void *)( rand()%100);34 value = (void *)(size_t)(rand()%100); 35 35 status = pthread_setspecific(key, (void *) value); 36 36 if ( status != 0) { … … 40 40 } 41 41 pthread_mutex_lock(&value_mutex); 42 total_value_getspec += ( int)value;43 total_value += ( int)pthread_getspecific(key);42 total_value_getspec += (size_t)value; 43 total_value += (size_t)pthread_getspecific(key); 44 44 pthread_mutex_unlock(&value_mutex); 45 45 46 46 47 if (!(value = malloc( sizeof(Buffer))))47 if (!(value = malloc(BUFFSZ))) 48 48 printf("Thread %d could not allocate storage, errno = %d\n", 49 49 threadnum, errno); … … 60 60 61 61 if (getvalue != value) { 62 printf("getvalue not valid, getvalue=%d", (u_int64_t)getvalue);62 printf("getvalue not valid, getvalue=%p", getvalue); 63 63 return (void*)68; 64 64 } … … 76 76 77 77 int main() { 78 int getvalue;79 78 int status; 80 79 int i; … … 116 115 117 116 if (thread_stat[i] != 0) { 118 printf("bad thread status, thread %d, status=% d\n", i+1,119 ( u_int64_t)thread_stat[i]);117 printf("bad thread status, thread %d, status=%zd\n", i+1, 118 (size_t)thread_stat[i]); 120 119 } 121 120 } 122 printf("total value is % d, total value by pthread_getspecific is %d\n", total_value, total_value_getspec);121 printf("total value is %zd, total value by pthread_getspecific is %zd\n", total_value, total_value_getspec); 123 122 exit(0); 124 123 } // main
Note:
See TracChangeset
for help on using the changeset viewer.