RFR: Classic problem 02 producer consumer problem - second try

Michael Mirwaldt duke at openjdk.java.net
Tue Nov 9 00:16:00 UTC 2021


This sample implements some solutions from the wikipedia article about the producer-consumer-problem on https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem .
It contains these solutions:
- _OneProducerOneConsumer_ with semaphores
- _FlawedTwoProducersOneConsumer_ with semaphores in which the producers sometimes use the same index for their items and overwrite each others item in the buffer
- _FixedTwoProducersOneConsumer_ with semaphores which uses an extra lock for the index so that the producers never use the same index for their items
- _Lock_ doesn't use any sempahores but a reentrant lock with two conditions. It supports many producers and many consumers
- _AtomicIntegers_ neither uses any semaphores but two atomic integers and supports one producer and one consumer.

I have decided not to implement the last solution with finite-range single writer registers in the wikipedia article. It looked far too complicated to me.

-------------

Commit messages:
 - added initial draft of ClassicProblem_02_ProducerConsumerProblem for a PR
 - Merge branch 'openjdk:master' into master
 - Setting my user name and email
 - Merge branch 'master' of https://github.com/mmirwaldt/jcstress
 - Merge branch 'openjdk:master' into master
 - Merge branch 'openjdk:master' into master
 - reviewed ClassicProblem_01_DiningPhilosophers the first time
 - Merge branch 'openjdk:master' into ClassicProblem_01_DiningPhilosophers
 - improved comment and ResourceHierarchy solution in ClassicProblem_01_DiningPhilosophers
 - added OneDinerFewer solution to ClassicProblem_01_DiningPhilosophers
 - ... and 14 more: https://git.openjdk.java.net/jcstress/compare/10bb0008...055089b2

Changes: https://git.openjdk.java.net/jcstress/pull/103/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jcstress&pr=103&range=00
  Stats: 312 lines in 1 file changed: 312 ins; 0 del; 0 mod
  Patch: https://git.openjdk.java.net/jcstress/pull/103.diff
  Fetch: git fetch https://git.openjdk.java.net/jcstress pull/103/head:pull/103

PR: https://git.openjdk.java.net/jcstress/pull/103


More information about the jcstress-dev mailing list