Boost logo

Boost Users :

Subject: [Boost-users] How to use lock_guard
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2009-03-10 06:04:35


I'm tring to use lock_guard, but I have some doubts...

I have a method called OnDataReceived() which is called by another class
through a signal.

void ATDispatcher::OnDataReceived()
  boost::lock_guard<boost::mutex> lock(_mut);

  // Data received from RS232

  // .... CODE ....

  // unlock the mutex before notifications


The first time it's called, it works fine.
The second time the flow locks on the creation of the lock object.

In the caller class I have solved this declaring the lock in this manner:

  boost::mutex::scoped_lock lock(_mutex);

  while (true)
     //main loop

      // saving data to vector
      _read_buffer.append(buf, rd);

      //Unlock the mutex


but here because there is the worker thread loop, while in the called
class there is no loop.

Thanks for suggestions.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at