summaryrefslogtreecommitdiff
path: root/src/user/test/main.c
blob: ec14c21e2f4fc64cf14ba4b434206cd760a5df3f (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
#include <tce/syscall.h>
#include <stdlib.h>

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

	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(".");
	}
}

int main() {
	printk("(test app) malloc(42) = ");
	printk_hex((uint32_t)malloc(42));
	printk("\n");

	printk("(test app) Creating thread cascade (total 2**8 = 256 threads)\n");
	thread_new(thread_cascade, (void*)8);

	printk("(test app) Main thread now sleeping... forever...\n");
	while (1) {
		thread_sleep(1000);
	}
	return 0;
}