Code of protected actions can be executed by any thread of control?

Can you explain the following to me ?

An implementation may perform the sequence of steps of a protected action using any thread of control; it need not be that of the task that started the protected action (RM)

(book) Assume that the producer in the program using protected objects attempts to append an item to a full buffer. The entry call Buffer.Append will be enqueued, the producer task will be blocked and a consumer task will be allowed to execute. Eventually, the consumer task will take an item from the buffer. Upon completion of the body of Take, servicing of the entry queue can be done by the consumer task, as shown in the following diagram:

If the caller of the protected action does not execute the code, who does ? I can’t be arbitrary, and I can’t see why a completely unrelated thread would do it. I mean, when they execute on the same core it would be irrelevant, since in any case the calling task is blocked until completion of the action, no matter where it happens. But it matters in case of multicore, multiprocessor or fully distributed systems, right ?

The other task (the consumer), as citation explained. You do not need to switch back to the caller (the producer) in order to execute the action.

It is very relevant because you do not need to switch the context, which is expensive. The consumer task already owns the processor. It executes the action and continues with the data. The producer has no processor, but unblocked and can continue when it gets the processor back.

The idea is to execute the protected action by any involved task if the task is active. This reduces latency to zero.

Even if the tasks run on different cores they share memory. So some advantage is still there.

Then there is a requeue statement…

2 Likes