Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <signal.h>
- #include <stdio.h>
- #include <pthread.h>
- #include <sched.h>
- #include <sys/time.h>
- #define NUMTHRDS 3 // 9 threads
- pthread_t t [NUMTHRDS]; //thread array
- int CreatAndArmTimer(){
- // Create a timer associated with real-time signal
- mySignalEvent.sigev_notify = SIGEV_SIGNAL;
- mySignalEvent.sigev_signo = threadInfo->signalValue; //A value b/t SIGRTMIN and SIGRTMAX
- mySignalEvent.sigev_value.sival_ptr = (void *)&(threadInfo->timerId);
- ret = timer_create (CLOCK_MONOTONIC, &mySignalEvent, &threadInfo ->timerId);
- //disarmed when initiated
- // arming timer
- seconds = period/1000000;
- nanoseconds = (period - (sec * 1000000)) * 1000;
- timerSpec.it_interval.tv_sec = seconds;
- timerSpec.it_interval.tv_nsec = nanoseconds;
- timerSpec.it_value.tv_sec = seconds;
- timerSpec.it_value.tv_nsec = nanoseconds;
- ret = timer_settime (threadInfo ->timer_id, 0, & timerSpec, NULL);
- return ret;
- }
- static void *thread0(void *_){
- printf("hello1 \n");
- printf("Thread[0] \t Timer Delta [%i]us \t Jitter [%i]us", int Delta, int Jitter);
- }
- static void * thread1(void * _){
- printf("hello2 \n");
- printf("Thread[1] \t Timer Delta [%i]us \t Jitter [%i]us", int Delta, int Jitter);
- }
- static void * thread2(void * _){
- printf("hello3 \n");
- printf("Thread[2] \t Timer Delta [%i]us \t Jitter [%i]us", int Delta, int Jitter);
- }
- int main(void){
- pthread_create(&t[0], NULL, thread0, NULL);
- pthread_create(&t[1], NULL, thread1, NULL);
- pthread_create(&t[2], NULL, thread2, NULL);
- pthread_exit(NULL);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement