5 ms·
> Nim supports real threads with message passing channels (similar to Go). Could you specify what are the differences from Go, in this regard are, please?
by crypto-jeronimo 8y ago
> Nim supports real threads with message passing channels (similar to Go).
Could you specify what are the differences from Go, in this regard are, please?
- captainbland 8y agoSure - I'm no expert in concurrency in programming languages as such but here's my understanding: so Nim supports what are essentially native operating system threads but with a difference from most languages being that each thread has its own garbage collected heap. Nim supports shared memory if you so choose to use it with a shared heap. Nim also supports a channel based communication system similar to Go's. Nim also supports lighter-weight parallelism with the `spawn` (unsafe, unstructured parallelism which schedules a procedure to run in a thread pool) and `parallel` (lets you use a subset of the Nim language to create concurrency safe tasks) keywords which pass tasks to thread pools in the background. You can read more about Nim's concurrency here: https://nim-lang.org/docs/manual.html#parallel-spawn-spawn-statement https://nim-lang.org/docs/manual.html#parallel-spawn-spawn-s... Go has Goroutines which use less resources than threads on most operating systems while also taking advantage of multicore CPUs (I assume they must run in a thread pool running in the background?). It also supports a select case statement which is a nice bit of syntax sugar for managing multiple channels, which Nim doesn't support (although its macro system is pretty powerful, so you could plausibly come up with an equivalent). Go does not support shared memory communication as a language feature, although some libraries apparently give you that option.
- RX14 8y agoAll the goroutines share the heap, so go does support shared memory, it's just you're encouraged to use channels instead because they're easier to get right.