QUESTION: Are MESSAGE and CUSTOM block commands REENTRANT or not?

Issue #94 resolved
Turgut Guneysu created an issue

Hi John,

I was experiencing some timing related problems in some of my code and started looking into how MESSAGE blocks or CUSTOM blocks execute. I was wondering if on repetitive calling, do these calls queue or interrupt the previously called instances?

In SNAP! there is a control mechanism for re-entrant execution. How does microBlocks handle it?

My initial test indicate the code is NOT reentrant.

Comments (6)

  1. John Maloney repo owner

    When you say “message” blocks do you mean “broadcast” and “when _ received”? That mechanism is not reentrant nor is there any queuing. That is, if the script for a “when _ received” hat is already running when a matching broadcast occurs, then that broadcast is simply ignored. It doesn’t start a new task nor is the broadcast queued. If the script for the “when _ received” hat is not already running, a new task is started to run it. If there are multiple matching “when _ received” hats for a given broadcast, tasks are started for all of them (assuming they are not already running). The sender does not does not wait (block) until the receiver task(s) are done. Thus, broadcasts are “non blocking” and they can start zero, one, or many new tasks.

    Custom blocks are simply functions. The caller does not proceed until control is returned by the callee. Control is returned when execution reaches the end of the script or when an explicit return is done. Function calls are synchronous and they do not start a new task; they execute in the caller’s task. They can be recursive but the stack size is limited so the depth of the recursion is limited. The exact depth depends on the number of arguments and temporary variables used by each recursive call.

    Hope that answers your questions.

  2. Log in to comment