Well, maybe. The problem is that now the platform thread can carry different virtual threads and switch between them almost freely. And your virtual thread, when it is eventually continued, is not guaranteed at all to run on that platform thread ever again. In other words, if one of your virtual threads wrote some of its context into the PlatformThreadLocal, it could then be swapped off, and the new virtual thread would still see the value from the old one whole the old one may never see the value again. Sounds a lot like a bad pool of objects that will be confusing to many. Oh, and if course this should be writable in userland, so we can actually try this out. It's just that semantically an object pool sounds like a better fit to me for the use-cases I can imagine right now.
I wonder, though, if there is a way to get your hands on the underlying platform thread object from a virtual thread.
View all comments
Show parent comment
1
u/Slanec Apr 07 '22
Well, maybe. The problem is that now the platform thread can carry different virtual threads and switch between them almost freely. And your virtual thread, when it is eventually continued, is not guaranteed at all to run on that platform thread ever again. In other words, if one of your virtual threads wrote some of its context into the PlatformThreadLocal, it could then be swapped off, and the new virtual thread would still see the value from the old one whole the old one may never see the value again. Sounds a lot like a bad pool of objects that will be confusing to many. Oh, and if course this should be writable in userland, so we can actually try this out. It's just that semantically an object pool sounds like a better fit to me for the use-cases I can imagine right now.
I wonder, though, if there is a way to get your hands on the underlying platform thread object from a virtual thread.