Adding test case for multproducer async calls.
[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     // could just hardcode 4 0's, will eventually wrap this marshaller anyway                                         
21         syscall_desc_t* desc;
22     syscall_req_t syscall = {REQ_alloc, cleanup_handler, cleanup_data,
23                                                         SYS_cputs,{(uint32_t)s, len, [2 ... (NUM_SYSCALL_ARGS-1)] 0} };                          
24     syscall.cleanup = cleanup_handler;                                                                                  
25     syscall.data = cleanup_data;
26     async_syscall(&syscall, &desc);
27         return desc;
28 }
29
30 void *syscall_thread(void* arg)
31 {       
32         char testme ='a';
33         char buf[20] = {0};
34         sprintf(buf, "%d", pthread_self()->id );
35         char tid = buf[0];
36         syscall_desc_t* sysdesc;
37         syscall_rsp_t sysrsp;
38         sysdesc = sys_cputs_async(&tid, 1, NULL, NULL);
39         waiton_syscall(sysdesc, &sysrsp);
40 }
41
42 int main(int argc, char** argv){
43         int pid = sys_getpid();
44         pthread_t *my_threads = malloc(sizeof(pthread_t) * NUM_THREADS);
45         char testme = 't';
46         printf ("multi thread - init arsc \n");
47         init_arc(&SYS_CHANNEL);
48         for (int i = 0; i < NUM_THREADS ; i++)
49                 pthread_create(&my_threads[i], NULL, &syscall_thread, NULL);
50         
51         for (int i = 0; i < NUM_THREADS; i++)
52                 pthread_join(my_threads[i], NULL);
53
54         printf("multi thread - end\n");
55 }
56