NVIDIA / stdexec

`std::execution`, the proposed C++ framework for asynchronous and parallel programming.
Apache License 2.0
1.56k stars 159 forks source link

How to achieve execution agent local variable? #1259

Open RishabhRD opened 7 months ago

RishabhRD commented 7 months ago

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:

maikel commented 7 months ago

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.

lewissbaker commented 7 months ago

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