Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "kernel.h"
  4. #include <time.h>
  5.  
  6. mailbox *mb;
  7. void task3();
  8.  
  9. void task1(){
  10. char data2;
  11.  
  12. printf("Data2 success %d \n", receive_wait(mb, &data2));
  13. if(data2%2 == 0){
  14. create_task(task3, ticks()+20);}
  15. else{printf("Data2: %d \n", &data2);}
  16. terminate();
  17.  
  18.  
  19. }
  20.  
  21. void task2(){
  22.  
  23. int data = 1;
  24. int i;
  25.  
  26. for(i = 0; i < 100; i++){
  27. printf("Task1 success %d \n", send_wait(mb, &data));
  28. data = rand() %100 + 1;
  29. create_task(task1, ticks()+20);
  30. wait(5000);
  31.  
  32. }
  33. terminate();
  34. }
  35.  
  36. void task3(){
  37. char data3;
  38.  
  39. printf(" Data3 Success: %d \n", receive_wait(mb, &data3));
  40.  
  41. printf("Data3: %d \n", &data3);
  42. terminate();
  43. }
  44.  
  45.  
  46. int main()
  47. {
  48. if(init_kernel() != 1){
  49. while(1);
  50. }
  51. create_task(task2, 150);
  52. srand(time(NULL));
  53. mb = create_mailbox(2, sizeof(int));
  54. if(mb == NULL){
  55. while(1);
  56. }
  57.  
  58. run();
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement