carrier local

Alan Bateman Alan.Bateman at oracle.com
Thu Apr 2 19:14:59 UTC 2020


On 02/04/2020 14:23, Alen Vrečko wrote:
> Hello, everyone.
>
> I have some thread local byte buffers. But now the threads are virtual and
> it defeats the purpose.
>
> Shouldn't the ThreadLocal act as carrier local? As ThreadLocal is
> effectively a private field for VirtualThread thus rendered useless?
>
> How do you access carrier thread via the API?
>
> I wish to list all the thread pool threads on server status page and have
> next to them some application level context data. This context is added
> using thread local. But now it doesn't work.
Virtual threads support thread locals so they can run existing code. It 
is possible to create virtual threads that don't allow thread locals to 
avoid footprint bloat but you quickly run into issues when you run 
something that expects to be able to set/get locals.

There is no support in the API for accessing the carrier thread's locals 
as it would not be safe to access these locals across scheduling points.

I can't tell from your mail what "doesn't work". Is this something that 
used thread pools and used thread locals to cache something across 
tasks? Are thread locals the right thing for these buffers? If you 
really want to have control over the resources managed by carrier 
threads then it requires using a custom scheduler as that gives you the 
"hooks" to run something before/after the tasks submitted to run the 
virtual thread between scheduling points.

-Alan


More information about the loom-dev mailing list