0

I am trying to re-write the classic producer-consumer algorithm using Windows libraries in C++. The snipped below was copied from a Java sample. Anyone know the equivalent of lock.notify and lock.wait using Windows Libraries such as EnterCriticalSection?

private Object lock = new Object();
public void produce() throws InterruptedException {
int value = 0;
while (true)
{
    synchronized (lock)
    {
        while(list.size() == LIMIT)
        {
            lock.wait();
        }
        list.add(value++);
        lock.notify();
     }
 }

thx!

gmmo
  • 2,577
  • 3
  • 30
  • 56
  • [Start with a look here](http://codereview.stackexchange.com/questions/84109/a-multi-threaded-producer-consumer-with-c11) and for reference, take a look at [std::mutex](http://en.cppreference.com/w/cpp/thread/mutex), and it's buddy [std::lock_guard](http://en.cppreference.com/w/cpp/thread/lock_guard), and [std::condition_variable](http://en.cppreference.com/w/cpp/thread/condition_variable), and – user4581301 Jul 16 '15 at 04:36
  • You're more likely to get an answer if you pretend we don't know anything about Java and describe the behavior of the functions you want to replicate. – Captain Obvlious Jul 16 '15 at 11:29

0 Answers0