-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread.c
53 lines (50 loc) · 1023 Bytes
/
thread.c
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
#include <base.h>
#include <thread.h>
#include <test/test-head.h>
static volatile int nr;
static int t0_thread(void *d)
{
int i;
for (i = 0; i < 10; i++) {
printk("thread %d %p\n",(int)d,&i);
thread_yield();
}
nr --;
return (int)d;
}
static int bad_addr(void *d)
{
thread_t *cur = current_thread();
printk("tid %d %s acc 0x4\n", cur->tid, cur->name);
*(volatile int *)0x4;
return 0;
}
static int busy_loop(void *d)
{
int i,j,loop = (int)d;
printk("busy loop %d\n", loop);
for (i = 0; i < loop; i++)
for (j = 0; j < 1000; j++)
asm volatile ("nop");
return 0;
}
static int thread(void)
{
thread_t *thd;
int i;
for (i = 0; i < 5; i++)
thread_create(t0_thread, (void*)(1000+i));
nr = i;
while (nr) {
printk("main yield %p\n", &i);
thread_yield();
}
thread_yield();
thd = thread_create(busy_loop, (void*)10000000);
thread_wait(thd);
thd = thread_create(bad_addr, NULL);
i = thread_wait(thd);
printk("bad_addr thread exit with %d\n",i);
return 0;
}
DEF_TEST(thread, 30, TESTF_REPEAT);