/* 
* TEMPLATE: task2mutex
* --------------------
* demonstrates critical region implemented by semaphore
* Task1 has higher priority than task2
* but both tasks sleeps a little in the loop
* Q: why are output as it is ?
* hint : no cpu power left for task2...
* Jens
*/

#include <snot.h>

struct k_t *pTask1, *pTask2, *pSem1, *pSem2;

char stak1[200];
char stak2[200];

void task1()
{
  while (1) {
    k_sleep(10);
    k_wait(pSem1,0);
    Serial.println("11");
    k_signal(pSem1);
  }
}

void task2()
{ 
  while(1) {
    k_sleep(80);
    k_wait(pSem1,0);
    Serial.println("22");
    k_signal(pSem1);
  }
}

void setup()
{
  Serial.begin(9600);
  k_init(2,2,0);
  k_bugblink13(1);
  pTask1 = k_crt_task(task1,9,stak1,200);
  pTask2 = k_crt_task(task2,10,stak2,200);

  pSem1 = k_crt_sem(1,10);
 
  k_start(10);
  // returning from k_start means SNOT  couldnt start
}

void loop() {/* not used */
}



