voron

experimental ARM OS
git clone git://git.2f30.org/voron
Log | Files | Refs | README | LICENSE

kmain.c (675B)


      1 #include <kernel.h>
      2 #include <sched.h>
      3 #include <semaphore.h>
      4 
      5 semaphore_t sem = SEMAPHORE_INIT(2);
      6 
      7 static void
      8 thread_func(void *arg)
      9 {
     10 	u32 i = 0, n = (u32)arg;
     11 	while (1) {
     12 		if (i == 5 * n) {
     13 			kprintf("thread %d waiting semaphore\n", n);
     14 			semaphore_wait(&sem);
     15 			kprintf("thread %d locked semaphore\n", n);
     16 		}
     17 		kprintf("thread %d  i: %d\n", n, i);
     18 		msleep(500);
     19 		i++;
     20 		if (i == 20 * n) {
     21 			i = 0;
     22 			semaphore_done(&sem);
     23 			kprintf("thread %d released semaphore\n", n);
     24 		}
     25 	}
     26 }
     27 
     28 void
     29 kmain(void)
     30 {
     31 	kprintf("voron initial stage\n\n");
     32 	kthread_create(thread_func, (void*)1);
     33 	kthread_create(thread_func, (void*)2);
     34 	kthread_create(thread_func, (void*)3);
     35 }