Cooperative vs preemtive scheduling of virtual theads

Andrey Lomakin lomakin.andrey at gmail.com
Mon Jun 8 16:51:36 UTC 2020


Guys,
I am very appreciate for the time which you spent on all those explanations
and feedbacks.
But couple of things still not complepletely clear for me. I will start one
by one.
As Ron wrote and the same can be read in "State of Loom" paper which he
published

>  "For example, a scheduler with a single worker platform thread would make
> all memory operations totally ordered, not require the use of locks, and
> would allow using, say, HashMap instead of a ConcurrentHashMap"


As Alan wrote

> Yes, it's possible in theory but unlikely in the current implementation
> because of the limitation that the thread is pinned while holding a
> monitor (ClassLoaders will almost always be holding a monitor when
> loading classes).


And I suppose when we say HashMap we mean any data structure which was not
designed to be shared between OS threads and do not perfrom any IO calls .
Like RB Tree, Fibonacci Heap and so on.
But data structures itself obviously can use their own classes, lets take
HashMap like more or less abstract example.
In current implementation of HashMap nodes can be presented as
entires contained inside of  linked list or inside of the tree (depends on
amount of hash collisions).
Let suppose that hash map is used to share state between virtual threads
which are executed by single carrier thread.
And amount of hash collisions for all nodes is bellow the threshould. Then
in one virtual thread we reach this threshould.

So basically I would like to discuss this pseudo code:

if(amoun_of_hash_collissions>= hahs_collisions_threshould) {
TreeNode treeNode = new TreeNode();
}

Also as far as I know JVM is not required to load any class before it  is
really used into code (I do not work on that level on daily basis so may be
I am wrong of course).
So creation of TreeNode object *theoretically* may introduce scheduling
point which may lead or may not lead (depends on details of implementation
of data structure, like copying of data into intermediate container before
addition to the TreeNode) to the inconsisitent state of the data structure.

What I want to understand is boundaries of abstraction which I can use to
create code which works as fast as possible. Could you explain what is
wrong with logic above and why usage of single thread carrier allowes usage
of data structures like HashMaps. I do wish that it will be possible (like
it is/was in quasar project) but I am eager to understand why.


On Mon, Jun 8, 2020 at 6:12 PM Alan Bateman <Alan.Bateman at oracle.com> wrote:

> On 08/06/2020 15:52, Ron Pressler wrote:
> > You should not make any assumptions about where scheduling points are.
> Thread.yield
> > is not currently specified, but we *may* specify it so that it
> guarantees returning
> > to the scheduler.
> >
> Just to add a bit more to this. The current implementation will return
> to the scheduler when the thread is not pinned. If pinned then it just
> continues.
>
> -Alan
>


-- 
Best regards,
Andrey Lomakin.


More information about the loom-dev mailing list