basically my program has 2 sets of threads, workers and jobs. Each job has an arrival time, then it is pushed onto a queue.
For the servers, I want them to constantly look for a job on the queue, once there is a job on the queue, only 1 worker takes it off and does its thing with it.
In main, all the worker threads are created first and then the job threads are created and synchronized (each pushing stuff on the queue). I can't get the timing right as the worker threads sometimes do things at exactly the same time OR the jobs aren't being pushed onto the queue at the right times (ie. job with arrival time 3 is pushed before job with arrival time 2). How can I do this using semaphores and/or mutexes?
I tried to put a mutex in the worker function but I don't really have a good handle on mutexes/semaphores..
Any ideas would be appreciated.
Thanks!
std::cout, this is pure C code. Are you aware that C++ is a lot more than just a C add-on? If you're so fond of C, that you even use thestructkeyword where C++ doesn't require it, but C does, then why not abandon streams in favor ofprintf()etc. and do pure C? As it is you make the C crowd unhappy for using streams, and the C++ crowd for using C except for the streams.