Boost logo

Boost Users :

Subject: [Boost-users] [boost-users][StateChart] event creation/destruction
From: Igor R (boost.lists_at_[hidden])
Date: 2009-02-25 07:25:21


Hello,

In my application I use a few async state-machines with lots of events. I'd
like to trace some events construction/destruction balance, so I define
them as follows:

volatile long eventCount;
template<class MostDerived> struct EvBase : sc::event<MostDerived>
{
 EvBase()
 {
  long c = InterlockedIncrement(&eventCount);
  somelog << c << std::endl;
 }
 ~EvBase()
 {
  long c = InterlockedDecrement(&eventCount);
  somelog << c << std::endl;
 }
};
// inherit EvBase directly
struct Ev1 : EvBase<Ev1> {};
struct Ev2 : EvBase<Ev2> {};
struct Ev3 : EvBase<Ev3> {};
// inherit EvBase indirectly
template<class MostDerived> struct EvIntermediate : EvBase<MostDerived>
{};
struct Ev4 : EvIntermediate<Ev4> {};
When I run the application, I see that at some stage the counter goes
negative, and its tendency is to get more and more negative.
I guess I don't realize something important about the sc::event, so I'd
appreciate enlightment on this.

Thanks,

Igor'.



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