Code Monkey home page Code Monkey logo

concurrent-printing-system-demo's Introduction

Concurrent Printing System - Demo

Demonstration of a concurrent printing system, that has several students that share a printer to print documents, and two technicians that refill it with paper and toner cartridges.

Contents:

The Java code uses Re-entrant Locks. PrintingSystem class has the main method, which can be used to run the demo.

The corresponding FSP processes are as follows:

const MAX_SHEETS = 3 // Maximum number of sheets in a printer

set PRINT_ACTIONS = {acquirePrint, print, acquireRefill, refill, release}

// Initialise printer with given number of sheets and continue
PRINTER (PAPER_COUNT = MAX_SHEETS) = PRINTER[PAPER_COUNT],
PRINTER[p : 0..PAPER_COUNT] = 
	if (p > 0)
	then (acquirePrint -> print -> release -> PRINTER[p-1])
	else (acquireRefill -> refill -> release -> PRINTER[MAX_SHEETS]).

// Initialise student and print given number of documents
STUDENT(DOCUMENT_COUNT = 1) = STUDENT[DOCUMENT_COUNT],
STUDENT[d : 1..DOCUMENT_COUNT] = (
	acquirePrint -> print[d] ->
		if (d > 1)
		then (release -> STUDENT[d-1])
		else (release -> END) // Prints the last document
) + PRINT_ACTIONS / {print/print[d:1..DOCUMENT_COUNT]}. // Exposes print[d] actions as just "print"

TECHNICIAN = (
	acquireRefill -> refill -> release -> TECHNICIAN |
	wait -> TECHNICIAN
) + PRINT_ACTIONS.

||PRINTING_SYSTEM = (s3: STUDENT(3) || s2: STUDENT(2) || t: TECHNICIAN || {s3, s2, t} :: PRINTER).

Implemented for the coursework of the module: Concurrent Programming (6SENG002W) in 2018, at Informatics Institute of Technology (IIT), Sri Lanka, in collaboration with University of Westminster.

Author: Senthuran Ambalavanar (github.com/senthuran16)

concurrent-printing-system-demo's People

Contributors

senthuran16 avatar

Watchers

 avatar  avatar  avatar

Forkers

sankakodda

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.