#include <serializer.h>
A Serializer is similar to a mutex (e.g. Spinlock) and guarantees mutually exclusive access to a shared resource. It has the benefit of better cache utilization because requests from different threads can be combined/aggregated and executed by the thread which first accessed the shared resource. Furthermore the code for your critical section can be executed asynchronously if you don't have to wait for it to finish.
Suppose you have a shared resource you can safely access it in the following way:
The equivalent code for a Spinlock/ScopedLock looks like this:
The code for critical sections is executed in order of the enqueues: If lambda A was enqueued before lambda B it will be executed before it, the order of execution will never be changed.
Public Member Functions | |
template<typename FN > | |
void | EnqueueAndWait (FN fn) |
template<typename FN > | |
void | Enqueue (FN fn) |
void EnqueueAndWait | ( | FN | fn | ) |
Enqueues a lambda or object with operator () and waits until it has finished. The callable must not return a value, the Serializer is low level and does not support error handling via Result<>.
[in] | fn | Callable object. |
void Enqueue | ( | FN | fn | ) |
Enqueues a lambda or object with operator (). This means the lambda might be asynchronously executed by a different thread and this method most likely returns before the lambda has been executed. The callable must not return a value, the Serializer is low level and does not support error handling via Result<>.
[in] | fn | Callable object. |