c++ - Multithreading program -
basically program has 2 sets of threads, workers , jobs. each job has arrival time, pushed onto queue.
for servers, want them job on queue, once there job on queue, 1 worker takes off , thing it.
in main, worker threads created first , job threads created , synchronized (each pushing stuff on queue). can't timing right worker threads things @ same time or jobs aren't being pushed onto queue @ right times (ie. job arrival time 3 pushed before job arrival time 2). how can using semaphores and/or mutexes?
i tried put mutex in worker function don't have handle on mutexes/semaphores..
any ideas appreciated.
thanks!
the q push q pop operation needs atomic i.e (is critical section). put under mutex acquire , mutex release. should you.
check posix thread tutorial understand mutex acquisition , release. use pthread tutorial
Comments
Post a Comment