0
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *t1(){
    long tid=9;
    printf("thread ID %ld",tid);
}
void *t2(){
    long tid=10;
    printf("thread ID %ld",tid);
}
int main()
{
    pthread_t thread1,thread2;
    int rc;
    int i=0;
    rc =pthread_create(&thread1,NULL,t1,NULL);
    if(rc)
        {
        printf("ERROR");
        exit();
        }
    pthread_create(&thread2,NULL,t2,NULL);
    return 0;

}

This is where I am at, I have created the threads and executed it but I don't know how to call those functions based on a timer.

mediocrevegetable1
  • 4,086
  • 1
  • 11
  • 33
arc
  • 1
  • 4
  • Hii, Are you looking for something like this ? https://stackoverflow.com/questions/43148664/execute-function-according-to-time – DevError404 Oct 18 '21 at 05:07
  • No i need to use itimerspec in C – arc Oct 18 '21 at 05:10
  • It's not clear whether you really want to create new threads periodically or whether you want to create the threads once and then have them print periodically. In either case can you just use [nanosleep](https://man7.org/linux/man-pages/man2/nanosleep.2.html)? – kaylum Oct 18 '21 at 05:36
  • Checkout this question: https://stackoverflow.com/questions/1157209/is-there-an-alternative-sleep-function-in-c-to-milliseconds – Leonardo Araujo Oct 18 '21 at 07:30
  • I have to ask - why are you continually creating threads on a timer instead of just creating two threads that loop with an appropriate sleep call?? – Martin James Oct 18 '21 at 17:11

0 Answers0