eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'UnlimitedSharedQueue':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: UnlimitedSharedQueue


Inheritance:

   Object
   |
   +--Collection
      |
      +--Queue
         |
         +--SharedQueue
            |
            +--UnlimitedSharedQueue

Package:
stx:libbasic2
Category:
Kernel-Processes
Version:
rev: 1.4 date: 2019/06/25 05:29:32
user: cg
file: UnlimitedSharedQueue.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


Like the superclass, SharedQueue, this provide a safe mechanism for processes to communicate.
They are basically queues, with added secure access to the internals,
allowing use from multiple processes (i.e. the access methods use
critical regions to protect against confusion due to a process
switch within a modification).

In contrast to SharedQueues, which block the writer when the queue is full,
instances of me grow the underlying container, so the writer will never block
(of course, the reader will still block in #next, if the queue is empty).

This kind of queue is eg. needed if the reader process itself wants to
add more (write) to the queue. 
For this, a limited sharedQueue would block the reader process (when writing),
if the queue is full, which would lead to a deadlock situation.


Related information:

    SharedQueue
    SharedCollection
    OrderedCollection
    Queue
    Semaphore
    Process
    CodingExamples::SharedQueueExamples

Instance protocol:

private
o  commonWriteWith: aBlock
common code for nextPut / nextPutFirst;
do NOT wait for available space, if the queue is full; instead resize as required.
After the put, signal availablity of a datum to readers.


Examples:


ATTENTION: Using a regular SharedQueue will lead to a deadlock when the reader writes itself. (you'll have to terminate the two processes in the process monitor):
  |reader writer q|
  
  q := SharedQueue new:10.
  
  reader :=
      [
          [
              |element|
              
              element := q next.
              element == true ifTrue:[
                  q nextPut:#xx.
                  q nextPut:#xx.
                  q nextPut:#xx.
              ].
              Transcript showCR:element.
          ] loop.    
      ] fork.

  writer :=
      [
          q nextPut:false.
          q nextPut:false.
          q nextPut:false.
          q nextPut:false.
          q nextPut:false.
          q nextPut:true.
          q nextPut:true.
          q nextPut:true.
          q nextPut:true.
          q nextPut:true.
          q nextPut:false.
          q nextPut:false.
          q nextPut:false.
          Transcript showCR:'writer finished'.
      ] fork.
this will not lead to a deadlock (you'll have to terminate the two processes in the process monitor):
  |reader writer q|

  q := UnlimitedSharedQueue new:10.

  reader :=
      [
          [
              |element|

              element := q next.
              element == true ifTrue:[
                  q nextPut:#xx.
                  q nextPut:#xx.
                  q nextPut:#xx.
              ].
              Transcript showCR:element.
          ] loop.    
      ] fork.

  writer :=
      [
          q nextPut:false.
          q nextPut:false.
          q nextPut:false.
          q nextPut:false.
          q nextPut:false.
          q nextPut:true.
          q nextPut:true.
          q nextPut:true.
          q nextPut:true.
          q nextPut:true.
          q nextPut:false.
          q nextPut:false.
          q nextPut:false.
          Transcript showCR:'writer finished'.
      ] fork.


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Sat, 27 Apr 2024 01:02:58 GMT