Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Racket support multithreading?

I want to write a multithreading program in Racket that actually utilizes multiple processes with shared memory space like pthread in C. Racket provides "thread", but it only uses one process to execute multiple threads. It also provides "subprocess" for executing new programs via command line that runs on multiple processes, but those programs cannot share the same memory space.

like image 857
mangpo Avatar asked Jun 26 '14 01:06

mangpo


1 Answers

Don't do that.

Racket does provide parallelism via futures and places, but they do not provide (unrestricted) shared memory spaces. If you want to send data from one thread to another, use a place channel.

As Greg Hendershott points out, you can send a shared vector via a place channel, which provides a shared space to use. (But that's not the same thing as sharing all the memory references, which is what someone familiar with, say, Java-style threading might expect. And the latter is what my "don't do that" refers to.)

If you really want to use pthread-like threading, Guile does provide them, but then you won't be using Racket any more. ;-)

like image 123
Chris Jester-Young Avatar answered Oct 13 '22 11:10

Chris Jester-Young