Possible Re-entrancy?

Greetings -

Trying to figure out whether or not I have problem brewing.

I have a state machine that manages an IPC channel. When single stepping, I can do an IPCSocket.Connect. If there is no listener present, I will get an socket error event back before I get to the end of the function (single stepping). The state machine function is then called from the socket error event (before the original function call has reached the end of the function).

I don’t know whether or not this happens when running full speed, and I am not sure how to tell if it does.

The question is whether or not this will cause any problems if it does occur in full speed operation.

Jim Wagner
Oregon Research Electronics

The error event should be called before Connect returns. You should check for an error after you attempt to connect. In any case, the state shouldn’t change, should it? It would be “not connected” before the connection attempt, and the error event should set it back to “not connected” or perhaps “error detected”. Both of which would indicate no connection is present.

Right, but while single stepping, the error is triggered before it does anything more after the connect action. Thus, the state machine is re-called before it has a chance to reach its normal end., I think that I have everything constructed so that the state comes out right, but I am concerned about what state the function is in, and whether it will try to come back and finish.


Without seeing your code it’s hard to say. But if you are afraid of re-entrancy you may want to add some checks and test test test.

That is the correct sequence. You call Connect, Connect triggers the Error event, the Error event executes, then Connect returns to the code that called it. You should code so that it doesn’t cause a problem.

OK, think I am doing that. Will recheck with fine-tooth comb.


If you have “DoEvents” in a GUI app then you very likely can/will get reentrancy issues with events
AVOID it like the plague in GUI apps for exactly this reason