Aaaaa988

mainfix

Dec 24th, 2020
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <sys/neutrino.h>
  6. #include <sys/syspage.h>
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. int child;
  12. int coid;
  13.  
  14. void* funcOne(void *){
  15. qtime_entry* per_sec = SYSPAGE_ENTRY(qtime);
  16. long long PER_SEC = per_sec -> cycles_per_sec;
  17.  
  18. printf("Thread[1]: send empty msg\n");
  19. long start = ClockCycles();
  20. MsgSend(coid, NULL,0 ,NULL, 0);
  21. long stop = ClockCycles();
  22. long res = stop - start;
  23.  
  24. double t = (double) res / PER_SEC;
  25. printf("Thread[1]: Cycles = %lld\n",res);
  26. }
  27.  
  28. void* funcTwo(void *){
  29. int rovid = MsgReceive(child, NULL, 0, 0);
  30. printf("Thread[2]: received msg\n");
  31. MsgReply(rovid, 0, NULL, 0);
  32. }
  33.  
  34. int main(){
  35. int thread[2];
  36. child = ChannelCreate(0);
  37. coid = ConnectAttach(0,0,child,0,0);
  38.  
  39. pthread_create(&thread[0], 0, func1, NULL);
  40. pthread_create(&thread[1], 0, func2, NULL);
  41.  
  42.  
  43. usleep(10000);
  44. return 0;
  45. }
RAW Paste Data