News for hackers. Stuff that matters.
Re:Using Java's Project Loom to build more reliable distribu... by ackfoobar on Monday May 09, 2022 @11:40PM (#31323169)
> all N threads that were spawned were tied to a single kernel thread. It also required cooperative multithreading, where one green thread may need to yield.

This is pretty much how JavaScript operates. You can consider calling an async function as spawning a user-level "thread"; chained-up callbacks are the same thing, but with manual CPS transform.

This has always perplexed me. Why N:1 threading is hated, but Node.JS is so loved?

Re:Using Java's Project Loom to build more reliable distribu... by kaba0 on Tuesday May 10, 2022 @02:03AM (#31323969)
You can still introduce very hard to debug blocking operations in nodejs, which will cause the whole runtime to slow down.
Re:Using Java's Project Loom to build more reliable distribu... by _ZeD_ on Tuesday May 10, 2022 @02:00AM (#31323954)
no.

javascript has exactly 1 thread (with the exception of web workers, but they are a pain to use)

the whole idea is to not have to relies on "async" stuff.

Re:Using Java's Project Loom to build more reliable distribu... by ackfoobar on Tuesday May 10, 2022 @03:45AM (#31324562)
>> single kernel thread

> This is pretty much how JavaScript operates

> javascript has exactly 1 thread

No disagreement here. I understand what you are saying. Would be great if you had tried to understand what I said.

Maybe my explanation is lacking. Let me quote pron.

> Again, threads — at least in this context — [...] refer only to the abstraction allowing programmers to write sequences of code that can run and pause.

https://cr.openjdk.java.net/~rpressler/loom/Loom-Proposal.ht...

An kernel thread running code line-by-line is a "thread"; callbacks that are sequenced (and have the dreaded pyramid indentation hell) forms a "thread"; when an async function is called there is also a "thread".

In JavaScript the latter two kinds of "threads" are run by one single kernel thread, i.e. N:1 threading.

Re:Using Java's Project Loom to build more reliable distribu... by _ZeD_ on Thursday May 12, 2022 @12:02AM (#31349145)
No. Callbacks are not a form of threads. Async is not a form of threads.
Re:Using Java's Project Loom to build more reliable distribu... by ackfoobar on Thursday May 12, 2022 @12:40AM (#31349376)
If you take the word "thread" to mean only "OS thread", then of course you are right, in the most boring way.

If you agree that Project Loom virtual threads are threads, consider this. When pluggable executor is available, you start a few of virtual threads, confining them in the UI thread. Semantically, how are they different from calling async functions in JavaScript?

---

>> abstraction allowing programmers to write sequences of code that can run and pause.

> No. Callbacks are not a form of threads. Async is not a form of threads.

Simply a "No" adds nothing to the conversation. Do you not see that they are "sequences of code that can run and pause"? Or do you not agree with the wider meaning of the word "thread"?