public class WorkStealingStructure<T> extends IStructure<T> implements IWorkStealing
IStructure.Backoff, IStructure.Node<T>
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.Long,IDEStructure<T>> |
dataQueues |
protected java.util.Map<java.lang.Long,java.lang.Long> |
dataQueuesMapping |
protected MultiThreadedRandomizer |
randomizer |
abort
Constructor and Description |
---|
WorkStealingStructure(int numOfThreads) |
WorkStealingStructure(int numOfThreads,
boolean debug) |
Modifier and Type | Method and Description |
---|---|
void |
add(T item)
add a object of type T
|
void |
add(T item,
int i)
Add a item to a data queue
Algorithm get operating system thread ID get local queue (mapping) assign item to own queue if available otherwise pick a random data queue if i != -1, then add item to given data queue |
static WorkStealingStructure<PTask> |
createForThreadPool(int numOfThreads)
Factory method for creating a WorkStealingStructure for the ThreadPool
|
protected java.lang.Long |
getThreadId() |
boolean |
isEmpty()
Method to tell if the data structure is empty (contains no elements).
|
void |
registerThread()
Add a thread to the data queue mapping
|
T |
remove()
Remove a item from one data queue
Algorithm
get operating system thread ID get local queue (mapping) remove item from own queue if the item is equal to null pick a random victim queue (iterate over all queues) return item |
get, shutdown
protected java.util.Map<java.lang.Long,IDEStructure<T>> dataQueues
protected java.util.Map<java.lang.Long,java.lang.Long> dataQueuesMapping
protected MultiThreadedRandomizer randomizer
public WorkStealingStructure(int numOfThreads)
public WorkStealingStructure(int numOfThreads, boolean debug)
public void add(T item)
IStructure
add
in class IStructure<T>
public void add(T item, int i)
add
in class IStructure<T>
item
- add this item to one data queuei
- if you want to add the item to a data queue of your choice use
the number of the data queue [0..numOfThreads], otherwise (-1,
PJob.SERIAL) add it to the own data queue or pick a random oneprotected java.lang.Long getThreadId()
public boolean isEmpty()
IStructure
isEmpty
in class IStructure<T>
public T remove()
remove
in class IStructure<T>
public void registerThread()
registerThread
in interface IWorkStealing
registerThread
in class IStructure<T>
public static WorkStealingStructure<PTask> createForThreadPool(int numOfThreads)
numOfThreads
-