Does LLVM provide any means for implementing green flows / light processes?

I am studying the development of a parallel language with support for light processes ("green threads") in the spirit of Erlang using LLVM as a native code generator. Lightweight processes are allocated for OS threads in M: N models, and it should be possible to steal between threads (i.e. Processes should be represented by a data structure that can be transferred between threads if necessary). At the same time, there can be a very large number of processes, so processes should not take up a lot of memory, and switching between them should be as fast as possible. In addition, it should be fairly simple to β€œpause” an easy process when switching contexts or garbage collection. I understand that Erlang has an LLVM backend, but I can find very little literature on its implementation; can anyone describe to me how this is possible?

+7
programming-languages llvm green-threads
source share
2 answers

I do not have much experience with LLVM or Erlang.

But I implemented such a system in langauge programming called PARLANSE. Yes, making context switches cheap is hard.

More on this SO answer: fooobar.com/questions/35330 /.

What little knowledge I have in LLVM may seem difficult. Which you need to generate context switching code. I'm not sure LLVM supports this directly. This, of course, is not what is easy to do when generating pure C-code, because language primitives do not allow you to get into the machine / thread state very well.

he turned over, so Klang, trying to support the capabilities of C ++ 14, must definitely stumble on the "C ++ native" streams. There must be support for context switching so that this can be done, so maybe someone has already or already dealt with this problem.

0
source share

LLVM is not directly related to the implementation of this type of system. There are many interfaces for languages ​​with constructs that are lower for LLVM IR.

LLVM is simply a compiler technology for generating native code for a single thread of execution. Implementation of context switching, proper stack creation (cactus stacks or other methods) and other problems primarily depend on the runtime environment and the environment.

The only exception is support for run-time call synthesis to expand the stack when necessary, and potentially split the stack into non-contiguous regions. As stated in the comments, LLVM has some support for this, although it is less tested. However, your interface can also control the use of the stack to avoid the need for LLVM support.

0
source share

All Articles