Would it be possible to use processes sharing memory created by clone3 to create domains ? Each domain would have a different pid, allowing to send signals from one domain to another or to use alarm for each domain ? This is probably not available on all architectures, but could be a possible optional feature for linux, like a Domain.create_pid
?
You might remember that this is somewhat how “LinuxThreads” worked. There were many problems with that, not least performance. There were correctness issues too, e.g. with semaphores. Linux moved past LinuxThreads to “NPT” threads, for good reasons.
I think clone3
system call as made some progress since and can implement thread where the only difference is the distinct pid and as a consequence the signal behaviour. Actually clone3 is available from Rust, which is probably a sign ?
What I really wanted is to be able to do a premptive scheduler under linux, so I need an effect to be automatically trigerred on each domain periodically, and I only could think of sigalarm to do that.
I’m not following: isn’t the point of the new multi-core runtime that threads that are in different domains are preemptively scheduled? Heck, they can be running concurrently if they’re running on different cores right? So why would clone3 help at all?
ETA: oh, perhaps you mean that you want to implement a preemptive scheduler in Caml? That is to say, you want to use effects to freeze a lightweight thread, and switch to another lightweight thread And do so preemptively without cooperation from the threads. I must say, that’s pretty dangerous stuff And I would not be surprised that you end up in trouble. At least back in the JVM, There were various rules about positions In the code where a thread could stop to ensure that all pointers were “in representation”. It’s been a long time, so I’m not going to try to think of more issues, But that’s the first one that came to mind. I remember in the original IBM JVM signals were used to stop threads for global garbage collection, And we had to be very very careful because Threads could be entering or leaving native code and those needed to be handled specially. There are a lot of tricky corner cases when using signals, is all I’m saying. I think I read where someone said that signals were a generalization of control-C, with all that is bad about that.
I implement, for simple_httpd, a scheduler above domains. This means I may have 1000 threads handling 1000 connections running on 5 domains. The scheduler is very nicely implemented thanks to the effect module. I use fd event and select to do all the scheduling, but a thread that as no blocking IO and that does not call the yield function I provide will never be scheduled. I really would like to be able to implement a preemptive scheduler.
Yes, your ETA is right. And my scheduler (or the one of EIO) are working quite well. Just premption is missing.