Scoped variables

Brian Goetz brian.goetz at
Sun Dec 9 15:49:41 UTC 2018

> Or backing up further, how about a discussion of use cases that should
> be covered?

The conversation on scoped variables came out of another conversation, so maybe we should back up and start there.  

Right now, we’ve got ThreadLocal.  It is usually used as an approximation for what we really wan but we don’t have.  TL is what we’ve got, so we use it for a lot of things.  Ron and Alan spent some time categorizing the various use cases, and we looked at them and asked which of them are good uses and which are abuses, and for those that are abuses, what a better mechanism might be.  I’ll defer to Ron and Alan to provide a more complete list, but I’ll sketch out some canonical examples from each category (probably forgetting one): 

 - Proxy for processor-local
   - Contention-avoidance schemes
 - Proxy for frame-local
   - Transaction IDs, caller context, etc (EE uses this ubiquitously)
   - Other framework-specific implicit arguments or context
 - Caches
   - Objects that are expensive to create, such as SimpleDateFormat
 - True thread-local
   - Mostly only apply to mechanisms that own and manage the threads, like FJ pools

What this list tells us is that most uses of TL are really abuses of some form or another, so we started looking into what the right mechanisms are (scoped vars, processor locals) so that people would be less tempted to use the wrong mechanism when a better one is available.  

(Stepping back further, the bigger goal here is that, if we have the right mechanisms, we don’t have to make such heroic efforts to make fibers support thread locals, meaning that we will get to the fiber mechanism we really want, rather than the one tied to the legacy of what we have.) 

More information about the loom-dev mailing list