Is there a class which more directly represents "b...
# announcements
b
Is there a class which more directly represents "block until a condition is met" behavior? Or is the idea to just use
CountdownLatch
with a value of 1?
n
Can someone else signal when a change has been made which might cause the condition to have been met? (typical)
if so, this sounds like a condition variable
If not then i'm not sure how you can do better than polling (possibly though I'm completely misunderstanding)
b
Yeah I thought there was a ConditionVariable but I didn't see it...the result I saw was an Android thing
But that's the idea, yeah
So I was looking at wrapping a CountdownLatch with a value of 1 to act more like a conditionvariable, but it seems like there must be some existing class for that.
I do need to support the 'waiter' completing immediately if the condition is already met.
n
ah ok, not familiar with wha'ts available on android
just speaking from general multithreading knowledge
b
Sorry, to be clear I'm not on android
Ah, gotcha
n
ah, I see 🙂
Well, CV should support that, CV's should always support that
CV's typically have a
wait
call that supports a predicate; they check the predicate before sleeping
b
Ok, that wasn't my memory from posix-style CVs but it's been a while
n
CyclicBarrier might be helpful...
n
at a lower level, you might want to offer wait with no predicate, to more efficiently help construct more multi threading primitives
b
My use case is pretty simple, I think I'll go with CountdownLatch (or a simple wrapper which hard-codes the countdown value to 1) for now and see what needs come up in the future