signalListenerCount in OMNeT++ 5.1.1

145 views
Skip to first unread message

Florian Kauer

unread,
May 19, 2017, 7:43:09 AM5/19/17
to omn...@googlegroups.com
Hi,
I was just trying to port our code to OMNeT++ 5.1.1. However, I stumbled
upon an error where I don't know exactly know I should handle it.

what(): ASSERT: Condition '(int)signalListenerCount.size() ==
lastSignalID+1' does not hold in function 'registerSignal' at
ccomponent.cc:414

It occurs when I register a signal during static initialization in an
external library in the same way it is done for example in ccomponent.cc:
simsignal_t PRE_MODEL_CHANGE =
cComponent::registerSignal("PRE_MODEL_CHANGE");

The relevant code of ccomponent.cc is this:
if (cStaticFlag::insideMain()) { // otherwise signalListenerCount[] may
not have been initialized by C++ yet
signalListenerCount.push_back(0);
ASSERT((int)signalListenerCount.size() == lastSignalID+1);
}

The main problem is that insideMain is false during static
initialization of other signals, but true during static initialization
of an external library (opp_loadlibrary is called inside main). So the
lastSignalID already contains many registered signals, but none is
inside signalListenerCount.

So my question are:
- What is this signalListenerCount anyway?
- How can it possibly happen that cStaticFlag::insideMain() is true, but
the ASSERT does not fire, because many signals WILL already be
registered (at least those of cCompoenent itself)?

Greetings,
Florian

P.S.: The same issue is also the problem of this Stack Overflow post:
http://stackoverflow.com/questions/43053391/opp-runall-q-runnumbers-returned-nonzero-exit-status-omnet

Attila Török

unread,
May 19, 2017, 8:37:12 AM5/19/17
to OMNeT++ Users
Hi Florian!

Thank you for your report and detailed analysis of the problem.
Could you try inserting this line:

EXECUTE_ON_STARTUP(cComponent::clearSignalState());

Into ccomponent.cc, right after the definition of cComponent::signalListenerCount, then rebuilding OMNeT++, and checking if the assertion still fails?

Attila



--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.

Florian Kauer

unread,
May 19, 2017, 3:10:41 PM5/19/17
to omn...@googlegroups.com
Hi Attila,
thank you for your fast response!
I have no idea why, but that actually seems to help, thanks!

Greetings,
Florian

On 05/19/2017 02:36 PM, Attila Török wrote:
> Hi Florian!
>
> Thank you for your report and detailed analysis of the problem.
> Could you try inserting this line:
>
> EXECUTE_ON_STARTUP(cComponent::clearSignalState());
>
> Into ccomponent.cc, right after the definition of
> cComponent::signalListenerCount, then rebuilding OMNeT++, and checking
> if the assertion still fails?
>
> Attila
>
>
> 2017-05-19 13:42 GMT+02:00 Florian Kauer <floria...@koalo.de
> <mailto:floria...@koalo.de>>:
> send an email to omnetpp+u...@googlegroups.com
> <mailto:omnetpp%2Bunsu...@googlegroups.com>.
> <https://groups.google.com/group/omnetpp>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "OMNeT++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to omnetpp+u...@googlegroups.com
> <mailto:omnetpp+u...@googlegroups.com>.

Attila Török

unread,
May 21, 2017, 3:57:00 PM5/21/17
to OMNeT++ Users
A really quick explanation:

signalListenerCount is a vector that keeps track of how many listeners are attached to each signal registered so far. Since this vector is directly indexed by the signal IDs, it must always have the same number of elements in it as there are signals registered. The ASSERT that failed checks for this.

However, for signals registered before the main function is called, counters can't be safely added to the vector because it might not have been properly initialized yet. The vector is resized to become consistent with lastSignalID in clearSignalState, some time before the network is built.

However, static initializers in dynamically loaded libraries are executed between these two points: Already in main, but before clearSignalState is called, this is why the ASSERT fails. The EXECUTE_ON_STARTUP macro will make it be called before the libraries are loaded.

I hope it is clearer now. I can elaborate if you (or any future reader) are interested, but for now, I didn't feel it's necessary.
Attila


>
>
> --
> You received this message because you are subscribed to the Google
> Groups "OMNeT++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> Visit this group at https://groups.google.com/group/omnetpp.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+unsubscribe@googlegroups.com.

Florian Kauer

unread,
May 22, 2017, 4:17:38 AM5/22/17
to omn...@googlegroups.com
Hi Attila,
perfect explanation, thanks! The missing link in my understanding was
the fact, that the vector will be resized to ensure consistency later.

I would be happy to see this fix in future versions of OMNeT if you
think it is reasonable.
For my case, it looks like moving the signal registration out of the
static initialization fixes the problem also for other users of our
framework without requiring them to apply this patch.

Greetings,
Florian

On 21.05.2017 21:56, Attila Török wrote:
> A really quick explanation:
>
> signalListenerCount is a vector that keeps track of how many listeners
> are attached to each signal registered so far. Since this vector is
> directly indexed by the signal IDs, it must always have the same number
> of elements in it as there are signals registered. The ASSERT that
> failed checks for this.
>
> However, for signals registered before the main function is called,
> counters can't be safely added to the vector because it might not have
> been properly initialized yet. The vector is resized to become
> consistent with lastSignalID in clearSignalState, some time before the
> network is built.
>
> However, static initializers in dynamically loaded libraries are
> executed between these two points: Already in main, but before
> clearSignalState is called, this is why the ASSERT fails.
> The EXECUTE_ON_STARTUP macro will make it be called before the libraries
> are loaded.
>
> I hope it is clearer now. I can elaborate if you (or any future reader)
> are interested, but for now, I didn't feel it's necessary.
> Attila
>
>
> 2017-05-19 21:10 GMT+02:00 Florian Kauer <floria...@koalo.de
> <mailto:floria...@koalo.de>>:
>
> Hi Attila,
> thank you for your fast response!
> I have no idea why, but that actually seems to help, thanks!
>
> Greetings,
> Florian
>
> On 05/19/2017 02:36 PM, Attila Török wrote:
> > Hi Florian!
> >
> > Thank you for your report and detailed analysis of the problem.
> > Could you try inserting this line:
> >
> > EXECUTE_ON_STARTUP(cComponent::clearSignalState());
> >
> > Into ccomponent.cc, right after the definition of
> > cComponent::signalListenerCount, then rebuilding OMNeT++, and checking
> > if the assertion still fails?
> >
> > Attila
> >
> >
> > 2017-05-19 13:42 GMT+02:00 Florian Kauer <floria...@koalo.de <mailto:floria...@koalo.de>
> > <mailto:floria...@koalo.de <mailto:floria...@koalo.de>>>:
> > send an email to omnetpp+u...@googlegroups.com
> <mailto:omnetpp%2Bunsu...@googlegroups.com>
> > <mailto:omnetpp%2Bunsu...@googlegroups.com
> <mailto:omnetpp%252Buns...@googlegroups.com>>.
> > Visit this group at https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>
> > <https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>>.
> > For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>
> > <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "OMNeT++ Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> > an email to omnetpp+u...@googlegroups.com
> <mailto:omnetpp%2Bunsu...@googlegroups.com>
> > <mailto:omnetpp+u...@googlegroups.com
> <mailto:omnetpp%2Bunsu...@googlegroups.com>>.
> > Visit this group at https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "OMNeT++ Users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to omnetpp+u...@googlegroups.com
> <mailto:omnetpp%2Bunsu...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "OMNeT++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to omnetpp+u...@googlegroups.com
> <mailto:omnetpp+u...@googlegroups.com>.

Rudolf Hornig

unread,
May 22, 2017, 5:05:29 AM5/22/17
to OMNeT++ Users
In fact, doing the registration during NON static initialization is recommended. The reason behind this is that the first 64 listener registered is handled specially (using a 64-bit bit field). This gives better performance when emitting a signal. If you register the signals in static blocks you have no control over the order of initialization (as it depends also on the order of the object files how the final executable is linked).

This is not a big problem in smaller projects where the total signal count is below 64, but in something like INET it's a bigger issue, because signals get initialized in static blocks even if they are not used at all during the actual simulation (because they belong to modules that are unrelated to your model. (like OSPF in a wireless simulation etc.). This is the exact reason why we have moved away from static init and hopefully INET does not use it anymore...

Long story short, register your signals in the module's initialization method so they are registered on-demand and you can ensure that only those are registered that are actually needed.
>     >     Visit this group at https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>
>     >     <https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>>.
>     >     For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>
>     >     <https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>>.
>     >
>     >
>     > --
>     > You received this message because you are subscribed to the Google
>     > Groups "OMNeT++ Users" group.
>     > To unsubscribe from this group and stop receiving emails from it, send
>     > Visit this group at https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>.
>     > For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>.
>
>     --
>     You received this message because you are subscribed to the Google
>     Groups "OMNeT++ Users" group.
>     To unsubscribe from this group and stop receiving emails from it,
>     Visit this group at https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>.
>     For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "OMNeT++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send

Florian Kauer

unread,
May 22, 2017, 6:22:11 AM5/22/17
to omn...@googlegroups.com
That sounds very reasonable, thanks, I will do it this way.

However, INET still has many registerSignal during static
initialization, at least in master and the integration branch, for
example src/inet/transportlayer/udp/UDP.cc

Greetings,
Florian
> > <mailto:floria...@koalo.de <mailto:floria...@koalo.de>>>:
> > > <mailto:omnetpp%2Bunsu...@googlegroups.com
> <mailto:omnetpp%252Buns...@googlegroups.com>
> > <mailto:omnetpp%252Buns...@googlegroups.com
> <mailto:omnetpp%25252Bun...@googlegroups.com>>>.
> > > <mailto:omnetpp+u...@googlegroups.com
> <mailto:omnetpp%2Bunsu...@googlegroups.com>
> > <mailto:omnetpp%2Bunsu...@googlegroups.com
> <mailto:omnetpp%252Buns...@googlegroups.com>>>.
> > > Visit this group at https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>
> > <https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>>.
> > > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>
> > <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> > --
> > You received this message because you are subscribed to the
> Google
> > Groups "OMNeT++ Users" group.
> > To unsubscribe from this group and stop receiving emails from it,
> <mailto:omnetpp%252Buns...@googlegroups.com>>.
> > Visit this group at https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>
> > <https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>
> > <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "OMNeT++ Users" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> <mailto:omnetpp%2Bunsu...@googlegroups.com>>.
> > Visit this group at https://groups.google.com/group/omnetpp
> <https://groups.google.com/group/omnetpp>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "OMNeT++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to omnetpp+u...@googlegroups.com
> <mailto:omnetpp+u...@googlegroups.com>.

Rudolf Hornig

unread,
May 24, 2017, 5:12:23 AM5/24/17
to OMNeT++ Users


On Monday, 22 May 2017 12:22:11 UTC+2, Florian Kauer wrote:
That sounds very reasonable, thanks, I will do it this way.

However, INET still has many registerSignal during static
initialization, at least in master and the integration branch, for
example src/inet/transportlayer/udp/UDP.cc

We should fix that for INET 4. Signal handling should be reviewed anyway.
 
>     >     >     send an email to omnetpp+unsubscribe@googlegroups.com
>     <mailto:omnetpp%2Bunsubscribe@googlegroups.com>
>     >     <mailto:omnetpp%2Bunsubscribe@googlegroups.com
>     <mailto:omnetpp%252Bunsubscribe@googlegroups.com>>
>     >     >     Visit this group at
>     https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>
>     >     <https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>>
>     >     >     <https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>
>     >     <https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>>>.
>     >     >     For more options, visit
>     https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>
>     <https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>>
>     >     >     <https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>
>     >     <https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>>>.
>     >     >
>     >     >
>     >     > --
>     >     > You received this message because you are subscribed to the
>     Google
>     >     > Groups "OMNeT++ Users" group.
>     >     > To unsubscribe from this group and stop receiving emails
>     from it, send
>     >     > Visit this group at https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>
>     >     <https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>>.
>     >     > For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>
>     >     <https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>>.
>     >
>     >     --
>     >     You received this message because you are subscribed to the
>     Google
>     >     Groups "OMNeT++ Users" group.
>     >     To unsubscribe from this group and stop receiving emails from it,
>     >     send an email to omnetpp+unsubscribe@googlegroups.com
>     <mailto:omnetpp%2Bunsubscribe@googlegroups.com>
>     >     <mailto:omnetpp%2Bunsubscribe@googlegroups.com
>     >     Visit this group at https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>
>     >     <https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>>.
>     >     For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>
>     >     <https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>>.
>     >
>     >
>     > --
>     > You received this message because you are subscribed to the Google
>     > Groups "OMNeT++ Users" group.
>     > To unsubscribe from this group and stop receiving emails from it,
>     send
>     > Visit this group at https://groups.google.com/group/omnetpp
>     <https://groups.google.com/group/omnetpp>.
>     > For more options, visit https://groups.google.com/d/optout
>     <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "OMNeT++ Users" group.
> To unsubscribe from this group and stop receiving emails from it, send

Attila Török

unread,
May 29, 2017, 9:18:34 AM5/29/17
to OMNeT++ Users
As Rudolf said before it's best to avoid this kind of usage, but the fix should be in the next OMNeT++ release, so it will work properly, even if not in the most optimal way in some cases.

Attila


    >     Visit this group at https://groups.google.com/group/omnetpp
    <https://groups.google.com/group/omnetpp>
    >     <https://groups.google.com/group/omnetpp
    <https://groups.google.com/group/omnetpp>>.
    >     For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>
    >     <https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>>.
    >
    >
    > --
    > You received this message because you are subscribed to the Google
    > Groups "OMNeT++ Users" group.
    > To unsubscribe from this group and stop receiving emails from it, send

    > Visit this group at https://groups.google.com/group/omnetpp
    <https://groups.google.com/group/omnetpp>.
    > For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.

    --
    You received this message because you are subscribed to the Google
    Groups "OMNeT++ Users" group.
    To unsubscribe from this group and stop receiving emails from it,

    Visit this group at https://groups.google.com/group/omnetpp
    <https://groups.google.com/group/omnetpp>.
    For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.


--
You received this message because you are subscribed to the Google
Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send

Visit this group at https://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages