Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost][thread] synchronization fails - why?
From: Roman Shmelev (rshmelev_at_[hidden])
Date: 2009-08-20 08:54:40


As it seems to me - it must work ok. At least this (simplified variant):

FILE* pConsole;
boost::mutex consoleMutex;

class logmsg
{
public:
  logmsg(const void* source, const char* msg)
  {
    boost::mutex::scoped_lock lock(consoleMutex);
    cout << msg << endl;
  }
};

Note that:
1) there are no variable params. Probably problem was in that you
haven't dealed with them (va_list, va_arg ...)
2) if you are creating logmsg in constructor of some global variable,
then consoleMutex can be created later and you will actually work not
with mutex, but with garbage in memory


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net