Object » SharedQueue
A SharedQueue provides synchronized communication of arbitrary objects between Processes. An object is sent by sending the message nextPut: and received by sending the message next. If no object has been put in the queue when a next message is sent, the process requesting the object will be blocked until one is sent.
The protocol of a SharedQueue resembles that of a ReadWriteStream. To avoid the use of inherited code that is not thread-safe, the class SharedQueue is defined as a direct subclass of Object.
contentsArray - Array
Together with the instance variables readPosition and writePosition
this instance variable implements a first-in first-out buffer. The elements with
indices in the range
readPosition to: writePosition - 1
readPosition - Integer
For
readPosition < writePosition
writePosition - Integer
This variable keeps the index of the array element that will take the next
element that is written into the queue.
accessProtect - Semaphore
This semaphore is used to implement exclusive access to the contents of the queue.
It ensures that at most one process accesses the instance variables contentsArray,
readPosition and writePosition.
readSynch - Semaphore
This semaphore counts the number of elements in the queue. It is used to
block requestors when the queue is empty.
new
answer a new empty shared queue with space for 10 items. The queue will
grow when it turns out that space for more than 10 elements is needed.
new: initialSize
answer a new empty shared queue with space for initialSize items.
The queue will grow when it turns out that space for more elements is needed.
nextPut: item
add the object item to the queue.
next
remove an item from the queue. The removed item is answered as
the message result. If the queue is currently empty, the sender
of the message will be suspendend until an item becomes available.
peek
answer but do not dequeue the item that will be fetched next
from the queue. For an empty queue, this message will immediately
answer nil.