Lecture Notes for Concurrent Programming

31 July 2002 - KWIC Indexing, Pipe-and-Filter Style


KWIC Indexing


KWIC Indexing


Filters


The Filter Template


Example Abstract Filter Methods


The Termination Interface


Pipe-and-Filter Termination.


The Pipe-and-Filter Termination Condition


Pipe-and-Filter Termination Class


Using Pipe-and-Filter Termination


Stopping Threads


Putting It All Together

class kwic {

  public static void main(String[] args)

    buffer b1, b2, b3

    StoppingThread threads[] = new StoppingThread[4]
    PAFTermination halter = new PAFTermination(4)

    InputFilter if = new InputFilter("input", b1)
    RotateFilter rf = new RotateFilter("rotate", b1, b2)
    SortFilter sf = new SortFilter("sort", b2, b3)
    OutputFilter of = new OutputFilter("output", b3)

    threads[0] = new StoppingThread(0, halter, if)
    threads[1] = new StoppingThread(1, halter, rf)
    threads[2] = new StoppingThread(2, halter, sf)
    threads[3] = new StoppingThread(3, halter, of)

    for (int i = 0; i < threads.length; i++)
      threads[i].start()

    if halter.disposition() != PAFTermination.normal
      System.out.println("Abnormal termination.")
      for (int i = 0; i < threads.length; i++)
	if threads[i].isAlive()
	  threads[i].interrupt()


Inventory


Points to Remember


This page last modified on 9 August 2002.