#mutex #reducer #buffer

buf-mutex

Buffered mutexes implementing the reducer parallel-programming pattern

4 releases

new 0.2.2 Apr 11, 2025
0.2.1 Feb 5, 2025
0.2.0 Feb 5, 2025
0.1.0 Feb 4, 2025

#366 in Concurrency

Download history 299/week @ 2025-01-31 91/week @ 2025-02-07 10/week @ 2025-02-14 6/week @ 2025-02-21 19/week @ 2025-02-28

371 downloads per month

Apache-2.0 OR LGPL-2.1-or-later

20KB
64 lines

Buffered Mutexes Implementing the Reducer Parallel–Programming Pattern

downloads dependents license Latest version Documentation

Sometimes, multiple threads need to update a shared value so frequently that the overhead of an atomic or a Mutex becomes a bottleneck. If, however, only the cumulative result of the update is important, and not any of the intermediate values, a BufMutex makes it possible to pass around multiple cloneable SharedBufMutexs containing a local value that can be updated without synchronization, and that will be combined into the global value when the SharedBufMutexs are dropped. This pattern works particular well with methods such as like Rayon's for_each_with, map_with, and so on.

Structures of this type are called reducers in OpenMP and reducer hyperobjects in Cilk; they fuel the inner workings of Rayon. However, Rayon does not expose them—you access them through a functional (or pull) interface (e.g., via the fold method). If you need an imperative (or push) interface (e.g., direct mutation methods) you can use a BufMutex.

Acknowledgments

This software has been partially supported by project SERICS (PE00000014) under the NRRP MUR program funded by the EU - NGEU. Views and opinions expressed are however those of the authors only and do not necessarily reflect those of the European Union or the Italian MUR. Neither the European Union nor the Italian MUR can be held responsible for them.

No runtime deps