Make arsc and local async calls use the same structure.
[akaros.git] / tests / arsc_mt.c
1 #include <rstdio.h>
2 #include <stdlib.h>
3 #include <pthread.h>
4 #include <unistd.h>
5 #include <vcore.h>
6 #include <parlib.h>
7 #include <ros/syscall.h>
8 #include <arc.h>
9 #include <stdio.h>
10
11 #define NUM_THREADS 4
12
13 pthread_t t1;
14
15 async_desc_t desc1;
16
17 syscall_desc_t* sys_cputs_async(const char *s, size_t len,                                             
18                      void (*cleanup_handler)(void*), void* cleanup_data)
19 {                                                                                                                     
20         return arc_call(SYS_cputs, s, len);
21 }
22
23 void *syscall_thread(void* arg)
24 {
25         char testme ='a';
26         char buf[20] = {0};
27         sprintf(buf, "%d", (pthread_self()->id % 10) );
28         char tid = buf[0];
29         syscall_desc_t* sysdesc;
30         sysdesc = sys_cputs_async(&tid, 1, NULL, NULL);
31         assert (-1 != waiton_syscall(sysdesc));
32 }
33
34 int main(int argc, char** argv){
35         int pid = sys_getpid();
36         pthread_t *my_threads = malloc(sizeof(pthread_t) * NUM_THREADS);
37         char testme = 't';
38         printf ("multi thread - init arsc \n");
39         init_arc(&SYS_CHANNEL);
40         for (int i = 0; i < NUM_THREADS ; i++)
41                 pthread_create(&my_threads[i], NULL, &syscall_thread, NULL);
42         
43         for (int i = 0; i < NUM_THREADS; i++){
44                 pthread_join(my_threads[i], NULL);
45         }
46
47         printf("multi thread - end\n");
48 }
49