daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Nov 21st, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <time.h>
  2. #include <signal.h>
  3. #include <stdio.h>
  4. #include <pthread.h>
  5. #include <sched.h>
  6. #include <sys/time.h>
  7.  
  8. #define NUMTHRDS 3  // 9 threads
  9. pthread_t t [NUMTHRDS]; //thread array
  10.  
  11. int CreatAndArmTimer(){
  12.  
  13.     // Create a timer associated with real-time signal
  14.  
  15.     mySignalEvent.sigev_notify = SIGEV_SIGNAL;
  16.     mySignalEvent.sigev_signo = threadInfo->signalValue; //A value b/t SIGRTMIN and SIGRTMAX
  17.     mySignalEvent.sigev_value.sival_ptr = (void *)&(threadInfo->timerId);
  18.     ret = timer_create (CLOCK_MONOTONIC, &mySignalEvent, &threadInfo ->timerId);
  19.     //disarmed when initiated
  20.    
  21.     // arming timer
  22.     seconds = period/1000000;
  23.     nanoseconds = (period - (sec * 1000000)) * 1000;
  24.     timerSpec.it_interval.tv_sec = seconds;
  25.     timerSpec.it_interval.tv_nsec = nanoseconds;
  26.     timerSpec.it_value.tv_sec = seconds;
  27.     timerSpec.it_value.tv_nsec = nanoseconds;
  28.     ret = timer_settime (threadInfo ->timer_id, 0, & timerSpec, NULL);
  29.  
  30.     return ret;
  31. }
  32.  
  33.  
  34.  
  35.  
  36. static void *thread0(void *_){
  37.         printf("hello1 \n");
  38.     printf("Thread[0] \t Timer Delta [%i]us \t Jitter [%i]us", int Delta, int Jitter);
  39. }
  40.  
  41. static void * thread1(void * _){
  42.         printf("hello2 \n");
  43.     printf("Thread[1] \t Timer Delta [%i]us \t Jitter [%i]us", int Delta, int Jitter);
  44. }
  45.  
  46. static void * thread2(void * _){
  47.         printf("hello3 \n");
  48.     printf("Thread[2] \t Timer Delta [%i]us \t Jitter [%i]us", int Delta, int Jitter);
  49. }
  50.  
  51.  
  52. int main(void){
  53.  
  54.     pthread_create(&t[0], NULL, thread0, NULL);
  55.     pthread_create(&t[1], NULL, thread1, NULL);
  56.     pthread_create(&t[2], NULL, thread2, NULL);
  57.  
  58.    
  59.     pthread_exit(NULL);
  60.    
  61.     return 1;
  62. }
RAW Paste Data
Top