Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-08

TObjectQueue with ability to dequeue arbitrary positions

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jorge Aldo G. de F. Junior

while working on my actor model concurrency for freepascal i met the following problem.

Each actor has a mailbox, that is made of the following components :

A standard TObjectQueue wich holds the messages
A TMultiReadExclusiveWriteSynchronizer that avoids race conditions while acessing the TObjectQueue.
A TEventObject that is used to signalize when a new object is pushed into the queue. Usefull if the actor wants a message but the queue is empty. (Writer triggers the signal and the reader sleeps until the signal is received).

Well, the problem i hit is the following :

Each message has a transactionID value that is used to differentiate among transactions. This is usefull when you need a synchronous transfer to happen on the fully assynchronous actor model.

An actor sends a request message and waits for a response message, both with the same transaction id.

While developing this framework i set myself the task of making it with two guarantees that are not much common on other actor model implementations :

Guaranteed message order and Guaranteed message delivery.

well well, thats where i need a TObjectQueue with ability to dequeue/inspect arbitrary positions :

When the object issues request it has to keep looping (until timeout) and dequeueing the last message from the mailbox, inspecting its transaction id for a match and requeueing the same message back into the mailbox if theres no match.

Thats the problem. When messages are requeued i lose message order guarantees (Very usefull). They are still guaranteed to be delivered, but not in order anymore.

Finishing the long story, i need a TObjectQueue that can access/extract arbitrary positions so as to avoiding losing the order of message delivery.

Does anybody have one already done/debugged and in GPL license ?

Thanks in advance,
J. Aldo.

Reply by email

waldo kitty
to Jorge Aldo G. de F. Junior

On 8/24/2012 14:57, Jorge Aldo G. de F. Junior wrote: [trim]

Show quoted text 8 lines
When the object issues request it has to keep looping (until timeout) and dequeueing the last message from the mailbox, inspecting its transaction id for a match and requeueing the same message back into the mailbox if theres no match. Thats the problem. When messages are requeued i lose message order guarantees (Very usefull). They are still guaranteed to be delivered, but not in order anymore.

when i got here, my first thought was why not add a queueID which is nothing more than a sequential serial number that gets reset to zero when the queue is empty... then keep the queue sorted on this ID... that should keep the queue in order... shouldn't it?

Reply by email