bacon-rajan-cc icon indicating copy to clipboard operation
bacon-rajan-cc copied to clipboard

How to use Cc<T> with multithreading?

Open mio-19 opened this issue 4 years ago • 4 comments

I want to implement a multi-threaded interpreter with Cc<T>. Does Mutex<Cc<T>> work?

mio-19 avatar Mar 28 '20 09:03 mio-19

Yes, Mutex<Cc<T>> should work.

jrmuizel avatar Mar 28 '20 13:03 jrmuizel

Actually, I might be wrong. There's a thread local buffer and it's pretty believable that things could break if you share Cc's across threads.

jrmuizel avatar Mar 28 '20 13:03 jrmuizel

We should create a Acc or something similar that can be sent or shared between threads. It seems like at the start of collect_cycle we can run a trace() over the nodes and lock all the ones that are going to take part in collect_cycles, then use trace() again to unlock all those nodes at the end of collect_cycles(). So that multiple collect_cycles from different threads can execute simultaneously if they are talking to independent nodes.

clinuxrulz avatar Apr 28 '20 00:04 clinuxrulz

I put up a prototype of what this could look like at https://github.com/jrmuizel/cc-mt

jrmuizel avatar May 30 '21 01:05 jrmuizel