This source file includes following definitions.
- thread_run
- receive_thread
- main
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 #include <sys/prex.h>
35 #include <ipc/ipc.h>
36 #include <stdio.h>
37
38 #define NR_THREADS 5
39
40 static char stack[NR_THREADS][1024];
41
42
43
44
45 static int
46 thread_run(void (*start)(void), void *stack)
47 {
48 thread_t t;
49 int error;
50
51 error = thread_create(task_self(), &t);
52 if (error)
53 return error;
54
55 error = thread_load(t, start, stack);
56 if (error)
57 return error;
58
59 error = thread_resume(t);
60 if (error)
61 return error;
62
63
64 return 0;
65 }
66
67
68
69
70 static void
71 receive_thread(void)
72 {
73 struct msg msg;
74 object_t obj;
75 int error;
76
77 printf("Receiver thread is starting...\n");
78
79 thread_setpri(thread_self(), 240);
80
81
82
83
84 error = object_lookup("test-A", &obj);
85
86 for (;;) {
87
88
89
90 printf("Wait message.\n");
91 msg_receive(obj, &msg, sizeof(msg));
92
93 printf("Message received.\n");
94
95
96
97 timer_sleep(1000, 0);
98
99 printf("Reply message.\n");
100 msg_reply(obj, &msg, sizeof(msg));
101
102 for (;;);
103 }
104 }
105
106 int
107 main(int argc, char *argv[])
108 {
109 object_t obj;
110 int error, i;
111
112 printf("IPC test for multi threads\n");
113
114
115
116
117 error = object_create("test-A", &obj);
118 if (error)
119 panic("failed to create object");
120
121
122
123
124 for (i = 0; i < NR_THREADS; i++) {
125 error = thread_run(receive_thread, stack[i] + 1024);
126 if (error)
127 panic("failed to run thread");
128 }
129 printf("ok?\n");
130 thread_setpri(thread_self(), 241);
131 for (;;)
132 thread_yield();
133 return 0;
134 }
|