Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

RocksDbQueue Threading Tweaks #940

Merged
merged 2 commits into from
Feb 21, 2019
Merged

Conversation

ajsutton
Copy link
Contributor

PR description

Since RocksDbQueue uses synchronized for its methods, it doesn't need to also use AtomicLong and AtomicBoolean. The close method wasn't synchronized but needs to be since it has to access the dequeueIterator field to close it.

private final Set<RocksDbTask<T>> outstandingTasks = new HashSet<>();

private final AtomicBoolean closed = new AtomicBoolean(false);
private boolean closed = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these vars need to be volatile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No because every access to them is within a synchronized section.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still getting up to speed on threading obviously :) . I didn't realize synchronized causes all the vars to be updated from main memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it has a read-fence on entry to the synchronized block and a write one on exit. So as long as both the writing thread and the reading thread used synchronized there's no need for volatile.

private final Set<RocksDbTask<T>> outstandingTasks = new HashSet<>();

private final AtomicBoolean closed = new AtomicBoolean(false);
private boolean closed = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Still getting up to speed on threading obviously :) . I didn't realize synchronized causes all the vars to be updated from main memory.

@ajsutton ajsutton merged commit 7423660 into PegaSysEng:master Feb 21, 2019
@ajsutton ajsutton deleted the rocksdb-threading branch February 21, 2019 21:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants