Hacker News new | ask | show | jobs
by zozbot234 1274 days ago
If you want good multithreaded support and don't care much about ensuring perfect thread-safety at all times, you can't beat Go for real-world use.
2 comments

Yes I like Go but I am yet to do any professional development in it.

Go is a M:N scheduler with M kernel threads and N lightweight threads

I wrote a 1:M:N lightweight scheduler which preempts hot loops. I don't know when Golang preempt goroutines outside of a channel send - I believe it's in stack growth or in other words when a method is called.

My userspace scheduler preempts while true and for loops by setting the looping variable to the limit.

I wrote it in Java, C and Rust.

https://GitHub.com/samsquire/preemptible-thread

Does anybody know if Nim loop variables can be easily mutated from another thread?

It looks they cannot

No, not directly but Nim supports async. Effectively it turns the function into an Iterator whose state can be passed around. Those are put into Futures.

Its possible to write your own async engine, or you could use the iterator yourself if you really wanted. It's actually not too hard.

Checkout: https://github.com/status-im/nim-taskpools

Edit: also Nim compiles to C, so its possible to do whatever you can do in C with a bit of fiddling. Also theres coro https://nim-lang.org/docs/coro.html

Elixir fits in here as well, if the workload is thread-bound and not computation bound.

I think Elixir's syntax and idioms are better than Go's, but that's personal preference.