-
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 freeze nor running freezer
a freezer 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 BooleangetIsPreempted()final BooleangetIsNormal()final BooleangetHasEvent()final StringgetName()final <T extends Any> Tpreempt(Function0<T> preemptiveTask)The freezer is preemptive, if there is at least one freezer task attempt enter the critical section without obtaining a lock, all task attempt 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
-
getIsPreempted
final Boolean getIsPreempted()
-
getIsNormal
final Boolean getIsNormal()
-
getHasEvent
final Boolean getHasEvent()
-
preempt
final <T extends Any> T preempt(Function0<T> preemptiveTask)
The freezer is preemptive, if there is at least one freezer task attempt enter the critical section without obtaining a lock, all task attempt 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()
-
-
-
-