antonpuz
antonpuz

Reputation: 3316

call to specific thread in C

In my multi thread project i have several threads running simultaneously, the only waiting function i could find is pthread_join but it does not invoke a specific thread, but instead it blocks the current running thread until the thread that I passed as parameter to pthread_join was over. i am looking for a way to invoke a specific one.

typedef struct proc{
    int sys_number; //unique node ID i give the thread
    pthread_t process; 
} thread;

thread proccesses[N];

thread = pthread_create(&(proccesses[i].process), NULL, printme, &(proccesses[i].sys_number));

then when i want to call lets say proccesses[i].process i use:

pthread_join(proccesses[0].process, &status);

but instead it runs all the processes that were opened and waiting, i am looking for the equivalent of waitpid in processes.

EDIT: I am looking for a way to choose which thread will run next

Upvotes: 0

Views: 368

Answers (1)

liuyu
liuyu

Reputation: 1404

I believe you can implement a simple pause() / resume() controller for each thread via mutex and condition variables.

Upvotes: 2

Related Questions