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


                       
                                                                   
                            

                            
                                                                    
                                    

                                  
                                                                    
                                    
                 
                                             
                            
                             
                                                           
                                             
                            
                                                           
                                                                   
                            
         



                  






                              


                        
                                      






                                              
                                                                             
                                      
                                             
 
                   
                           

                                        
                                                                                                   
 

                                

                 
#include <tce/syscall.h>
#include <stdio.h>

int threads = 1;

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(">");
		threads += 2;
		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--;
}

void useless_thread(void* d) {
	while(1) {
		printk("~");
		schedule();
	}
}

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

	printk("(test) Creating thread cascade (total 2**5 = 32 threads)\n");
	thread_new(useless_thread, 0);
	thread_new(thread_cascade, (void*)5);

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

	printf("(test) End.\n");

	return 0;
}