Reputation: 23
Using locks/condition variables how can you make the structure of a C program not to allow more than n threads to execute simultaneously the body of a function f?Say you have 60 created threads and only 10 are allowed to enter at once in the function. Could you write in pseudocode just as a general idea?
Upvotes: 0
Views: 94
Reputation: 180266
A semaphore, as @zwol suggested, is a good fit for this job:
sem_wait()
on the semaphore.sem_post()
exactly once before returning.Upvotes: 2
Reputation: 182769
You need a mutex, a condition variable, and an integer.
Upvotes: 2