You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What we need is that schedule() should fail (perhaps fatally, with exit()) if it is called with a logical action as the argument and it is not being called from within a reaction.
The challenge is how to do that without a highly non-portable strategy of examining the stack. One way, I suppose, is that each time a reaction is invoked, a global, thread-safe, map from worker thread to boolean is updated to indicate that the worker is invoking a reaction. The schedule can check that boolean when invoked. The map could be a simple array if there is a way for the schedule function to map a thread ID into an array index.
The text was updated successfully, but these errors were encountered:
I think there is a simpler solution than that. There could be a global variable in thread-local storage that points to the current reaction. Each worker would first set the variable to point to the reaction it is about to execute, then execute the reaction and then set the variable back to NULL. Since the variable would be in thread-local storage, each worker has its own copy and we don't need to worry about race conditions (i.e. no synchronization is required). When schedule() is called by the reaction, the schedule code can simply look up the thread-local variable to find the current reaction and inspect the declared effects.
This solution, however, would require the C11 standard. I am not sure if there is a portable mechanism for thread-local storage before C11.
I just realized that the issue is not about detecting whether the reaction is allowed to schedule the action, but just if a logical action is triggered from within any reaction. Then the thread-local variable could be a simple bool.
Edward wrote:
The text was updated successfully, but these errors were encountered: