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'.