[concurrency-interest] How to implement task-local variables (like thread local variables but for Fork/Join tasks)

Per Mildner perm at sics.se
Mon Aug 8 08:58:28 EDT 2016


Ping?

> On 09 Jun 2016, at 22:56, Per Mildner <perm at sics.se> wrote:
> 
> I need something that should behave like a thread-local variable but for a tree of RecursiveAction tasks.
> 
> That is, a task inherits the task-local variables from the task that created it. Looking up a task-local variable is done by traversing the chain of parent tasks, looking for special task instances that holds task local values.
> 
> I currently implement this by letting all tasks know their parent (the “current task”) which is passed to their constructor. This way I can traverse the chain of parents towards the root of the task tree.
> 
> Keeping track of the current task is done by making all tasks set and restore themselves as the “current task” in a thread-local variable in their RecursiveAction.compute() but that seems wasteful since it is done also when the the task is running in the same thread as its parent task.
> 
> So, any ideas how to implement this efficiently?
> 
> Even better, is there a way to make something like this work with the default pool?
> 
> Regards,
> 
> 
> Per Mildner
> Per.Mildner at sics.se
> 
> (I sent this earlier but it never seemed to arrive at the list. Sorry if it gets duplicated.)
> 
> 

Per Mildner                                     Per.Mildner at sics.se
Swedish Institute of Computer Science (SICS Swedish ICT)



More information about the Concurrency-interest mailing list