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.5 date: 2021/01/20 12:20:55
user: cg
file: UnlimitedSharedQueue.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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.

copyright

COPYRIGHT (c) 2016 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Wed, 08 May 2024 01:32:37 GMT