Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect async invocation of schedule on a logical action #253

Open
lhstrh opened this issue Jan 13, 2021 · 3 comments
Open

Detect async invocation of schedule on a logical action #253

lhstrh opened this issue Jan 13, 2021 · 3 comments
Labels
c Related to C target cpp Related to C++ target runtime Related to the runtime implementation

Comments

@lhstrh
Copy link
Member

lhstrh commented Jan 13, 2021

Edward wrote:

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.

@cmnrd
Copy link
Collaborator

cmnrd commented Jan 14, 2021

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.

@cmnrd
Copy link
Collaborator

cmnrd commented Jan 14, 2021

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.

@lhstrh lhstrh added c Related to C target cpp Related to C++ target labels Jan 14, 2021
@lhstrh lhstrh added the runtime Related to the runtime implementation label Jan 14, 2021
@lhstrh
Copy link
Member Author

lhstrh commented Jan 17, 2021

Since we already rely on pthreads, perhaps we should make use if their thread-local storage implementation:

https://en.wikipedia.org/wiki/Thread-local_storage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c Related to C target cpp Related to C++ target runtime Related to the runtime implementation
Projects
None yet
Development

No branches or pull requests

2 participants