Class PreemptChannelSupport
-
- All Implemented Interfaces:
public abstract class PreemptChannelSupportThe preemptive channel concurrency pattern, there are two channels: preemptive channel and normal channel
TODO: compare with ReadWriteLock
both channel allows multiple threads
new workers have to wait until there is no ready preemptive tasks nor running preemptive tasks
a preemptive task locks the working channel immediately, but have to wait to run util all workers are finished
|------ waiting ------------|- ready -|-------------- critical -------------------|---finished----
The entrance gate The exit gate
Preemptive channel: ------------#1--#1--#1------|----#2---|-----------------------------------#3-------|--- #4 -------- | | | Normal channel: ----*1----*1--*1------*1----|---------|-----------*2--*2------*2--*2---------------|--- *3 --------
#1 The waiting preemptive tasks #2 The ready preemptive tasks #3 The running preemptive tasks #4 The finished preemptive tasks
*1 The waiting workers *2 The running workers *3 The finished workers
-
-
Constructor Summary
Constructors Constructor Description PreemptChannelSupport(String name)
-
Method Summary
Modifier and Type Method Description final BooleanisPreempted()final BooleanisNormal()final BooleangetHasEvent()final StringgetName()final <T extends Any> Tpreempt(Function0<T> preemptiveTask)If there is at least one preemptive task in the critical section, all normal tasks must wait. final <T extends Any> TwhenNormal(Function0<T> task)final <T extends Any> TwhenNormalDeferred(SuspendFunction0<T> task)final UnitreleaseLocks()final StringformatPreemptChannelStatus()-
-
Constructor Detail
-
PreemptChannelSupport
PreemptChannelSupport(String name)
-
-
Method Detail
-
isPreempted
final Boolean isPreempted()
-
getHasEvent
final Boolean getHasEvent()
-
preempt
final <T extends Any> T preempt(Function0<T> preemptiveTask)
If there is at least one preemptive task in the critical section, all normal tasks must wait.
-
whenNormal
final <T extends Any> T whenNormal(Function0<T> task)
-
whenNormalDeferred
final <T extends Any> T whenNormalDeferred(SuspendFunction0<T> task)
-
releaseLocks
final Unit releaseLocks()
-
formatPreemptChannelStatus
final String formatPreemptChannelStatus()
-
-
-
-