How to achieve execution agent local variable?
RishabhRD opened this issue · 2 comments
Sometimes we need some variables to be execution agent local. Taking a use-case of parallel random number generation. If I want random number generator to be non-blocking for multiple threads, then each thread should have a separate copy of random generator.
For example, in case of a thread pool scheduler a thread_local random generator can be used. But that's not a generic solution.
I don't know how to handle the same with P2300. Is there some way to handle this kind of use-case?
I feel the use-case can be solved if I have 2 queries:
- Maximum number of tasks that can be executed concurrently at any moment of time. (can be unbounded too)
- Let's say the above query returns n. Then a query like current_execution_id that returns [0, n) representing on which execution agent task is currently at.
You can always invent your needed queries and add support for them in the receivers env of your schedule operation, at least if you own the execution context yourself.
But querying the receivers env is basically the way to access information that is only known at that time.
There was a proposal for an object-pool that was intended to address this kind of use-case.
See https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2774r1.pdf