annotate cbc_thread/cbc_thread_test.c @ 9:2ce34a5ff69b default tip

add pointer test
author taiki
date Tue, 08 Jan 2013 12:34:40 +0900
parents 1d2839ecabda
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
1d2839ecabda add thread test source.
taiki
parents:
diff changeset
1 #include <stdio.h>
1d2839ecabda add thread test source.
taiki
parents:
diff changeset
2 #include <stdlib.h>
1d2839ecabda add thread test source.
taiki
parents:
diff changeset
3 #include <pthread.h>
1d2839ecabda add thread test source.
taiki
parents:
diff changeset
4
9
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
5 typedef struct _DS {
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
6 int thread_no;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
7 int *data;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
8 } DS;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
9
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
10 __code start1()
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
11 {
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
12 printf("into cs \n");
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
13 }
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
14
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
15 void start(void *arg)
8
1d2839ecabda add thread test source.
taiki
parents:
diff changeset
16 {
9
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
17 DS *ds = (DS*)arg;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
18 printf("thread%d:\t%d\n", ds->thread_no, ds->data[0]);
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
19 goto start1();
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
20 }
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
21
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
22
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
23 int main(int argc, char* argv[])
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
24 {
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
25 pthread_t handle;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
26 DS ds;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
27
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
28 int data[2];
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
29
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
30 int i=0;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
31 for (; i < 2; i++) data [i] = i;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
32
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
33 ds.thread_no = 1;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
34 ds.data = data;
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
35
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
36 pthread_create(&handle, NULL, (void*)start, (void*)&ds);
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
37
2ce34a5ff69b add pointer test
taiki
parents: 8
diff changeset
38 pthread_join(handle, NULL);
8
1d2839ecabda add thread test source.
taiki
parents:
diff changeset
39 return 0;
1d2839ecabda add thread test source.
taiki
parents:
diff changeset
40 }