summaryrefslogblamecommitdiff
path: root/src/user/test/main.c
blob: d890850fb8c9d568d6e709f47ea1cb964e64a999 (plain) (tree)
1
2
3
4
5
6
7
8
9

                        
                   
 

                                
                              

                       

                  
                     

                                                                   

                            

                                                                    

                                  

                                                                    
                 

                                             
                                                           

                                             
                                                           

                                                                   
         

                  

 
            
                                                
 
                                                      
                                             
 
                                               




                                                                    

                 
#include <tce/syscall.h>
#include <tce/mem.h>
#include <stdlib.h>

static volatile int threads = 0;

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

	threads++;

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

	threads--;
}

int main() {
	printk("Hi world from test module !\n");

	printk("{1} Creating thread cascade len:4\n");
	thread_new(thread_cascade, (void*)7);

	printk("{1} Thread now sleeping...\n");
	while (1) {
		thread_sleep(1000);
		if (threads == 0) break;
	}
	printk("{1} Everybody seems to be done here, exiting...\n");
	return 0;
}