Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODETOOLS-7903060: jcstress: ProducerConsumer problem sample #104

Closed
wants to merge 9 commits into from
Closed

CODETOOLS-7903060: jcstress: ProducerConsumer problem sample #104

wants to merge 9 commits into from

Conversation

mmirwaldt
Copy link
Contributor

@mmirwaldt mmirwaldt commented Nov 14, 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.

This is my third try to avoid squash commits.


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jcstress pull/104/head:pull/104
$ git checkout pull/104

Update a local copy of the PR:
$ git checkout pull/104
$ git pull https://git.openjdk.java.net/jcstress pull/104/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 104

View PR using the GUI difftool:
$ git pr show -t 104

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jcstress/pull/104.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 14, 2021

👋 Welcome back mmirwaldt! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 14, 2021
@mlbridge
Copy link

mlbridge bot commented Nov 14, 2021

@mmirwaldt mmirwaldt marked this pull request as draft November 14, 2021 23:39
@mmirwaldt mmirwaldt marked this pull request as ready for review November 14, 2021 23:39
@mmirwaldt
Copy link
Contributor Author

mmirwaldt commented Nov 15, 2021

This PR looks much better now. Thanks for the advice, @shipilev .
I will do my next PRs that way, too.

Can you review this sample, please, @shipilev?

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a general comment about the style. The is sample code, it has to be fluent. Meaning, the reader has to be able to read the entire file as prose, being told what is shown, what are the expected results and why, what are the actual results. Look at how Basic* samples are written.

This, unfortunately, does not pass the bar for a good sample yet.

@mmirwaldt
Copy link
Contributor Author

mmirwaldt commented Nov 18, 2021

I must confess I am not sure how much description is enough for you and what is too much. It appeared to me in the last PRs you sometimes prefer rather a minimum than a maximum of explainations to avoid useless comments about obvious things. Maybe I am wrong.
What do you think about telling me where you want more description?
I don't want to waste your time (and mine neither) with too long texts.
Or do you really prefer the opposite? (I mean you tell me what I must remove from the texts)

Btw: I always try to be short on my answers for you because I believe you don't like to read long texts from me.

@mmirwaldt
Copy link
Contributor Author

Maybe it's a good idea to review again the sample ClassicProblem_01_DiningPhilosophers after this PR.
It has still got some "flaws" which you mentioned in this sample. We should be consistent in all samples.

@shipilev
Copy link
Member

Please change the PR title to "CODETOOLS-7903060: jcstress: ProducerConsumer problem sample" to get it hooked properly.

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just merged #105 that brings consistency to all current samples. Please pull from master, move your sample in the new location and try to match the style :)

@mmirwaldt mmirwaldt changed the title ClassicProblem_02_ProducerConsumerProblem - third try CODETOOLS-7903060: jcstress: ProducerConsumer problem sample Nov 21, 2021
@mmirwaldt
Copy link
Contributor Author

Please change the PR title to "CODETOOLS-7903060: jcstress: ProducerConsumer problem sample" to get it hooked properly.

Done.

@openjdk
Copy link

openjdk bot commented Nov 21, 2021

@mmirwaldt this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout ClassicProblem_02_ProducerConsumerProblem-3
git fetch https://git.openjdk.java.net/jcstress master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added merge-conflict Pull request has merge conflict with target branch and removed merge-conflict Pull request has merge conflict with target branch labels Nov 21, 2021
Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there.

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not there. Please match the style of the previous samples exactly.

@mmirwaldt
Copy link
Contributor Author

Which results?
I cannot see any

          RESULT        SAMPLES     FREQ      EXPECT  DESCRIPTION
            true  6,325,295,104  100.00%  Acceptable  Trivial.

for other tests than FlawedTwoProducersOneConsumer.
I can only see

(ETA: in 00:01:40; at Do., 2021-12-09 21:14:35)
(Sampling Rate: 8,09 M/sec)
(JVMs: 0 starting, 4 running, 1 finishing)
(CPUs: 12 configured, 12 allocated)
(Results: 434 planned; 359 passed, 0 failed, 0 soft errs, 0 hard errs)

How can I enable this output for all other tests?

I have added the separators but I miss the results.

@mmirwaldt
Copy link
Contributor Author

I am confused. Some integration tests don't run anymore. I cannot imagine any last change causing that.

@shipilev
Copy link
Member

How can I enable this output for all other tests?
I have added the separators but I miss the results.

Say -v to jcstress invocation: java -jar jcstress.jar ... -v.

@mmirwaldt
Copy link
Contributor Author

mmirwaldt commented Dec 10, 2021

How can I enable this output for all other tests?
I have added the separators but I miss the results.

Say -v to jcstress invocation: java -jar jcstress.jar ... -v.

Ah thank you, @shipilev!

I have added the results for all the other tests.

Please feel free to ask for further changes.
If I have accidentally resolved one of your changes although it's still wrong,
then please be patient with me and unresolve that issue with a comment.

@mmirwaldt
Copy link
Contributor Author

Any update, @shipilev?

Comment on lines +124 to +137
void producer() {
produce();
produce();
}

@Actor
void consumer() {
consume();
consume();
}

@Arbiter
public void fake(Z_Result r) {
r.r1 = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmirwaldt , It does not seem to be good to have "all outcomes are acceptable".

Have you considered producing messages with different values so you can tell which one was consumed?

For instance: r1=produce(1); r2=produce(2); and then r3=consume(); r4=consume();.

Then you could verify:

  1. "1, 2, 1, 2" is acceptable
  2. all others states are forbidden.

The same would apply to the other samples.

WDYT?

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, this is acceptable.

@openjdk
Copy link

openjdk bot commented Jan 3, 2022

⚠️ @mmirwaldt the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout ClassicProblem_02_ProducerConsumerProblem-3
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Jan 3, 2022

@mmirwaldt This change now passes all automated pre-integration checks.

After integration, the commit message for the final commit will be:

7903060: jcstress: ProducerConsumer problem sample

Reviewed-by: shade

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@shipilev) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 3, 2022
@mmirwaldt
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jan 11, 2022
@openjdk
Copy link

openjdk bot commented Jan 11, 2022

@mmirwaldt
Your change (at version f121d15) is now ready to be sponsored by a Committer.

@shipilev
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Jan 11, 2022

Going to push as commit 0f28604.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 11, 2022
@openjdk openjdk bot closed this Jan 11, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jan 11, 2022
@openjdk
Copy link

openjdk bot commented Jan 11, 2022

@shipilev @mmirwaldt Pushed as commit 0f28604.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@mmirwaldt mmirwaldt deleted the ClassicProblem_02_ProducerConsumerProblem-3 branch January 11, 2022 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
3 participants