Boost logo

Boost :

From: Ashok Thirumurthi (athirumurthi.news_at_[hidden])
Date: 2005-11-01 16:12:21


Dear Boost,

Doug hinted in the signals FAQ that it is possible to make a thread-safe
version of the library. While such a beast may not be in the works, I was
wondering if I could write my own layer to serialize calls to the signals
library.

Typically, we wrap signals using a class as simple as:

 class NKNEF_ENTRY CImageLoadedEvt : public CImageEvt
 {
  typedef boost::signal<void(const ImageLoadData&)> sigNotify_ImageLoaded;

  public:
  NKNEF_CALL CImageLoadedEvt();
  virtual NKNEF_CALL ~CImageLoadedEvt();
  void NKNEF_CALL Connect(const sigNotify_ImageLoaded::slot_type& slot);
  void NKNEF_CALL Notify(ImageLoadData& data);

 private:
  sigNotify_ImageLoaded signal;
 };

void NKNEF_CALL CImageLoadedEvt::Connect(const
CImageLoadedEvt::sigNotify_ImageLoaded::slot_type& slot)
{
 signal.connect(slot);
}

void NKNEF_CALL CImageLoadedEvt::Notify(ImageLoadData& data)
{
 signal(data);
}

Can a wrapper be designed to achieve thread-safe use of the signals library?
For instance, a critical section could guard concurrent operation of the
Connect and Notify methods as well as the destructor...

Thanks in advance for your advice,

- Ashok Thirumurthi


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk