upvote
By shared queue I mean that the queue doesn't belong to any single task or actor.

Each actor owns its own queue, and is the only reader. This makes it a many-to-one queue.

> Whenever the message queues may be used by multiple threads, which is always on modern CPUs, the 3 kinds of shared message queues must use certain methods to allow concurrent accesses, which are different for the 3 kinds of queues.

This is exactly what actor systems like Erlang avoid. The Erlang VM handles preemptive multitasking for the actors it manages, without using OS threads. This eliminates a lot of concurrency issues, and is a big part of why Erlang systems have such a reputation for reliability.

You can think of it like a green thread system where each thread has its own private message queue.

> but they must still use atomic instructions in the right way, to avoid data corruption.

This is only an issue because the message queues you're talking about are implemented separately from the OS, so there are no guarantees about concurrency behavior. This is exactly what the actor model solves for.

reply
OK, with your definition for "shared queue" what you said initially was correct, but by "shared data structure" I understand that the access to it is shared between multiple active entities, even if the data structure is owned by only one of those entities, hence the miscommunication.

In general, in programs it does not matter much where you put artificial borders of ownership between entities, but whether the access to a resource is shared or exclusive has a crucial impact on the required code.

If threads are not visible to the programmer who writes the code for an actor, there are 2 cases. The first is when threads really do not exist, in which case the VM is single-threaded and executed on a single core of a modern CPU, so the achievable performance is modest, but there is no need for handling concurrency.

The second case is when the VM is in fact multi-threaded, which, as you say, must be the case for Erlang, but it manages the scheduling of the threads itself, and the allocation of actors to threads, in a manner transparent for the programmer.

In this case the VM must include code for managing concurrent accesses from multiple hardware threads to the message queues, so they still are shared-access queues, even if their implementation is provided by the VM.

reply