← Back to context

Comment by mgaunard

13 hours ago

I find it better to model that as an Actor than a mutex, but I guess it's inherently the same thing, except the actor also allows asynchronous operations.

You can go full circle and also make operations on a mutex asynchronous. Hence the realization that message passing and shared memory are truly dual.

  • The very idea of a mutex is that it is synchronous. You wait until you can acquire the mutex.

    If it's asynchronous, it's not a mutex anymore, or it's just used to synchronously setup some other asynchronous mechanism.

    • A mutex is a way to guarantee mutual exclusion nothing more nothing less; You can recover synchronous behaviour if you really want:

          synchronized<Something> something;
          ...
          co_await something.async_visit([&](Something& x) {
              /* critical section here */ 
          });

      4 replies →