summaryrefslogtreecommitdiff
path: root/src/user/test/main.c
blob: 7ca4802a097a7d4f2426aab6e3952d72c29461b6 (plain) (blame)
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
57
58
#include <tce/syscall.h>
#include <stdlib.h>
#include <stdio.h>

int threads = 0;

void thread_cascade(void* d) {
	int n = (int)d;

	threads ++;

	if (d == 0) {
		//printk("{#} 0 cascade element started => end\n");
		printk("*");
	} else {
		if (n < 0) {
			//printk("{#} - cascade element started\n");
			printk("-");
			n = 0 - n;
		} else {
			//printk("{#} + cascade element started\n");
			printk("+");
		}
		//printk("{#} FORK + ...\n");
		printk(">");
		thread_new(thread_cascade, (void*)(n - 1));
		//printk("{#} FORK - ...\n");
		printk("<");
		thread_new(thread_cascade, (void*)(1 - n));
		//printk("{#} Thread cascade element finished.\n");
		printk(".");
	}

	threads--;
}

int main(char** args) {
	char**a;
	if (args != 0) {
		printk("args");
		for (a = args; *a != 0; a++) {
			printk(" - ");
			printk(*a);
		}
		printk("\n");
	}

	printk(" -> Creating thread cascade (total 2**4 = 16 threads)\n");
	thread_new(thread_cascade, (void*)4);

	while (1) {
		thread_sleep(100);
		if (threads == 0) break;
	}
	printk("\n -> Test process exiting. Press the super key to go to the home terminal.\n");

	return 0;
}