Hacker News new | past | comments | ask | show | jobs | submit login

Concurrency is like a single cook preparing many different recipes at the same time, and parallelism is multiple cooks in the same kitchen. Single-threaded processes can use async/await to context switch and it feels like parallelism but it's not unless you're executing each task to its own OS thread.

... and that didn't click for me until I understood that concurrency (async/await) and parallelism (multiple OS threads and processes) are different executions modes which the Tokio runtime in rust allows you combine those different modes.




Is multi threading (always) parallelism? I never questioned this but it just occurred to me that on a single-core CPU with a single execution thread, multithreading in user code is a noop? The code will run but won’t be any faster.


Yeah, async is a type of greenthreading.


When I think of green threads / fibers, its threading handled in user space. Where a stack is starts small and it can grow and its managed by the language’s runtime.


When I read async, I think about an event loop in a single thread.

Meanwhile when I read greenthreading, I think of lightweight threads like goroutines or Java's virtual threads.

Am I wrong?


Right. Both of them are running on a single OS thread with application-layer context switching. Async's form of context switching is the event loop, greenthreading's is something analogous to OS threads.

Maybe it's inaccurate to say async is a type of greenthreading and better to say it's a form of application-layer context-switching comparable to greenthreading.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: