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

[minor] Add pool.onQuiescent(cell) #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JanKoelzer
Copy link
Contributor

@JanKoelzer JanKoelzer commented Jan 31, 2018

Fixes #89 (but see discussion at #89 )

@JanKoelzer JanKoelzer changed the title Add pool.onQuiescent(cell) [minor] Add pool.onQuiescent(cell) Feb 2, 2018
success = poolState.compareAndSet(state, newState)
} else if (state.submittedTasks == 1) {
handlersToRun = Some(state.handlers)
handlersToRun = Some(state.quiescenceHandlers)
Copy link
Owner

Choose a reason for hiding this comment

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

This appears to be missing state.quiescenceCellHandlers. Otherwise, quiescence cell handlers are only run upon registration if the pool is already quiescent at that point.

Also, it would be good to add a test which would catch this issue (i.e., register quiescence cell handler when the pool is definitely not quiescent, and verify the handler runs eventually).

@@ -2,11 +2,15 @@ package cell

import java.util.concurrent.ConcurrentHashMap

import java.util.concurrent.CountDownLatch
Copy link
Owner

Choose a reason for hiding this comment

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

Combine with previous import clause.

val p1 = Promise[Boolean]()
val p2 = Promise[Boolean]()
pool.execute { () => { p1.success(true) }: Unit }
pool.onQuiescent { () => p2.success(true) }
Copy link
Owner

Choose a reason for hiding this comment

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

The type ascription in the call to execute is not so nice. Can we get rid of it?

val p1 = Promise[Boolean]()
val p2 = Promise[Boolean]()
pool.execute { () => { p1.success(true) }: Unit }
pool.onQuiescent { () => p2.success(true) }
Copy link
Owner

Choose a reason for hiding this comment

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

Ditto

val quiescenceHandlers: List[() => Unit] = List(),
val quiescenceCellHandlers: List[NextCallbackRunnable[_, _]] = List(),
val submittedTasks: Int = 0) {
def isQuiescent: Boolean =
Copy link
Owner

Choose a reason for hiding this comment

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

It would be better not to remove the pair of parens (), because isQuiescent is not pure (its result depends on the state of the pool). The Scala convention is to always have a pair of parens for impure methods.

def isQuiescent(): Boolean =
private class PoolState(
val quiescenceHandlers: List[() => Unit] = List(),
val quiescenceCellHandlers: List[NextCallbackRunnable[_, _]] = List(),
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we store NextCallbackRunnables, and not just closures like with quiescenceHandlers? One thing I'm a bit skeptical about is that NextCallbackRunnable[_, _] is a wildcard type, adding complexity which I'm not sure is warranted.

@@ -12,11 +12,18 @@ import lattice.{ DefaultKey, Key, Updater }
import org.opalj.graphs._

import scala.collection.immutable.Queue
import scala.util.{ Success, Try }
Copy link
Owner

Choose a reason for hiding this comment

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

Unused import?

@JanKoelzer JanKoelzer force-pushed the onQcell branch 2 times, most recently from 4f44d4a to 367f4bb Compare March 30, 2018 20:02
@JanKoelzer
Copy link
Contributor Author

JanKoelzer commented Mar 30, 2018

All comments are displayed as outdated, which is not correct (prob. because of the new package/file structure).

This appears to be missing state.quiescenceCellHandlers. Otherwise, quiescence cell handlers are only run upon registration if the pool is already quiescent at that point.
Also, it would be good to add a test which would catch this issue (i.e., register quiescence cell handler when the pool is definitely not quiescent, and verify the handler runs eventually).

--You are right. I am going to address this.-- This issue should be fixed now, two tests have been added.

Why do we store NextCallbackRunnables, and not just closures like with quiescenceHandlers? One thing I'm a bit skeptical about is that NextCallbackRunnable[_, _] is a wildcard type, adding complexity which I'm not sure is warranted.

Along with every callback, we need to store the cell whose value is passed to the callback as soon as quiescence is reached. That's quite exactly, what NextCallbackRunnable is used for in onnext. Otherwise, we would need to add a new class Foo[K, V](val cell: Cell[K, V], val handler: V => Unit) and store a List[Foo[_, _]]. (I am not sure how to get rid of the wildcards.)

Unused import?

The imports you commented on are used. Am I missing unused once?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants