-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_specific.c
More file actions
49 lines (41 loc) · 956 Bytes
/
example_specific.c
File metadata and controls
49 lines (41 loc) · 956 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
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
#include "co.h"
static int key1;
static int key2;
static int key3;
void f1(void *unused)
{
void *value = (void *)(unsigned long)coid();
printf("myid = %d\n", coid());
co_setspecific(key1, value);
co_setspecific(key2, value+1);
co_setspecific(key3, malloc(sizeof(int)));
yield();
printf("key1 %u\n", co_getspecific(key1));
printf("key2 %u\n", co_getspecific(key2));
printf("key3 %016llx\n", co_getspecific(key3));
}
void f(void *unused)
{
int i=5;
key1 = co_key_create(NULL);
key2 = co_key_create(NULL);
key3 = co_key_create(free);
printf("%d %d %d\n", key1, key2, key3);
while(i>0) {
printf("i=%d\n", i);
cocreate(16*1024, f1, NULL);
i--;
yield();
}
}
void main()
{
cocreate(16*1024, f, NULL);
while(coloop());
}