4 ms·
Does Racket support "real" multithreading yet? I remember looking at their documentation a few years ago and it only had support for a green-threading thing, w
by tombert 7y ago
Does Racket support "real" multithreading yet? I remember looking at their documentation a few years ago and it only had support for a green-threading thing, which (along with the first-class hashmaps) steered me towards Clojure.
- mruts 7y agoYou can use futures, which have access to underlying OS threads. They don’t share a memory space though. There’s also an Actor library called Goblins which is nice, but I’m not sure if can use multiple cores.
- gus_massa 7y agoFutures are difficult to use, because if you allocate or you call any of the "forbidden" primitives the thread will block and resume automatically when it is safe to do the operation. They are good for numerical work, but you have to pay a lot of attention writing code with futures. It's more easy to use places, you can run whatever you want in places, but the communication between places is restricted and they have a big startup time (something like a quarter of a second) so if you create one, ensure that you are going to use it for a long time.
- deleted 7y ago[deleted]
- masukomi 7y agoi _believe_ it does not CURRENTLY _but_ it's pretty far along with moving its lower layers to Chez Scheme which _does_ have native threading.
- samth 7y agoYes, Racket support using multiple cores/OS threads. There are two mechanisms -- shared memory parallelism that is limited in what operations the threads can execute in parallel (called futures in Racket) and shared-nothing parallelism with message passing, more like Erlang (called places in Racket). Most real work using parallelism in Racket uses places.
- tombert 7y agoI guess I was confused by this [1], specifically: Racket supports multiple threads of evaluation. Threads run concurrently, in the sense that one thread can preempt another without its cooperation, but threads currently all run on the same processor (i.e., the same underlying operating system process and thread). Is this documentation out of date or am I looking in the wrong place? [1] https://docs.racket-lang.org/reference/eval-model.html#%28part._thread-model%29 https://docs.racket-lang.org/reference/eval-model.html#%28pa...
- neilv 7y agoHere's two places to start, for the various options (sorry it's two separate manuals): https://docs.racket-lang.org/guide/parallelism.html https://docs.racket-lang.org/guide/parallelism.html https://docs.racket-lang.org/reference/concurrency.html https://docs.racket-lang.org/reference/concurrency.html Of course, you can also do it the old-fashioned way, with multiple Racket processes running services, being workers behind a proxy/frontend, possibly on multiple hosts, etc.
- samth 7y agoThat's about the `thread` construct specifically, which as it says is green threads. Mostly people who are spreading work across multiple cores will have a few places that communicate, each of which has multiple threads to handle internal concurrency.
- tombert 7y agoFair enough! That's what I get for giving up after the first piece of documentation. Maybe I'll give Racket another try....
- JoelMcCracken 7y agoYes and no. Its not that great. A big part of the motivation to rewrite atop Chez was to be able to expose more parallelism.