-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimple.c
More file actions
56 lines (51 loc) · 902 Bytes
/
simple.c
File metadata and controls
56 lines (51 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "uthread.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
static volatile int x = 0;
/*
print:
thread 1: 0
thread 2: 1
thread 3: 2
thread 4: 3
thread 5: 4
thread 1: 5
thread 2: 6
thread 3: 7
thread 4: 8
thread 5: 9
thread 1: 10
thread 2: 11
thread 3: 12
thread 4: 13
thread 5: 14
thread 1: 15
thread 2: 16
thread 3: 17
thread 4: 18
thread 5: 19
thread 1: 20
thread 2: 21
thread 3: 22
thread 4: 23
thread 5: 24
*/
void test_func(void* _arg){
int arg = (intptr_t ) _arg;
for(int i=0;i<5;i++){
printf("thread %d: %d\n",arg,x);
x++;
uthread_yield();
}
}
int main(){
init_uthreads();
uthread_create(test_func,(void*)1,NULL);
uthread_create(test_func,(void*)2,NULL);
uthread_create(test_func,(void*)3,NULL);
uthread_create(test_func,(void*)4,NULL);
uthread_create(test_func,(void*)5,NULL);
schedule();
return 0;
}