Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Producer/Consumer model equal Actor?

So lately I've been reading a lot of article about how concurrent programming is hard, and how concurrent programming with shared state is near impossible. So languages like Erlang (I think this is on, if not the question still makes sense) use the Actor model for concurrency and have no shared state between threads. Now in my time programming concurrent systems I've not found concurrency to be that hard - but in general I can fit almost any problem into the producer/consumer paradigm and live without much (if any) shared state. Although is that correct? Are the message queues between threads actually shared state? Or is the producer/consumer model of concurrent programming really a concrete example of the Actor model (that's my real question). Thoughts?

like image 645
Gandalf Avatar asked Aug 09 '11 19:08

Gandalf


People also ask

What is Producer consumer ordering model?

The producer/consumer (sometimes called pipelining) model is typified by a production line. An item proceeds from raw components to a final item in a series of stages. Usually a single worker at each stage modifies the item and passes it on to the next stage.

Is producer consumer a design pattern?

Producer-consumer is a classic concurrent programming design pattern, where processes are designated as either producers or consumers.

What is Producer and Consumer in semaphore?

The consumer removes the items from the buffer and consumes them. A producer should not produce items into the buffer when the consumer is consuming an item from the buffer and vice versa. So the buffer should only be accessed by the producer or consumer at a time.

What is producer consumer problem with example?

The Producer-Consumer problem is a classic synchronization problem in operating systems. The problem is defined as follows: there is a fixed-size buffer and a Producer process, and a Consumer process. The Producer process creates an item and adds it to the shared buffer.


1 Answers

Technically the shared messages represent the state of the overarching application, but only if the producers and consumers are themselves stateless (otherwise they simply represent the state(s) of the message-sharing medium/a). The producer/consumer model isn't so much an example of the actor model as each individual producer and consumer is. The producers (who may be consumers as well, either from the same shared message queues or from external sources) do what they do and spit out some message that gets queued up. The queue itself may be considered an actor, although a passive one, in that it recieves/holds messages, and may distribute them (or just wait for them to be taken). The consumers are actors in that they take/recieve messages from the shared queue, and do work based on those messages.

So basically my answer is that the producer/consumer model is not an example of the Actor model, but rather an example of a collection of Actors working in a shared environment.

like image 65
yoozer8 Avatar answered Oct 08 '22 05:10

yoozer8