简体   繁体   English

LLVM是否提供了实现“绿色线程”/轻量级进程的任何工具?

[英]Does LLVM provide any facilities for implementing “green threads”/lightweight processes?

I am looking into designing a concurrent language with support for lightweight processes ("green threads") in the vein of Erlang using LLVM as a native code generator. 我正在研究使用LLVM作为本机代码生成器来设计支持轻量级进程(“绿色线程”)的并发语言。 Lightweight processes are allocated to native OS threads in an M:N fashion, and work-stealing between threads should be possible (ie processes should be represented by a data structure that can be passed between threads if necessary). 轻量级进程以M:N方式分配给本机OS线程,并且线程之间的工作窃取应该是可能的(即,进程应该由可以在线程之间传递的数据结构表示,如果需要)。 A very large number of processes might exist at once, so processes shouldn't take up much memory and context switching between them should be as quick as possible. 可能同时存在大量进程,因此进程不应占用大量内存,并且它们之间的上下文切换应尽可能快。 Furthermore, it should be rather simple to "pause" a lightweight process during context switches or if garbage collection occurs. 此外,在上下文切换期间或者如果发生垃圾收集,“暂停”轻量级进程应该相当简单。 I understand Erlang has an LLVM backend, but I can find very little literature on its implementation; 我知道Erlang有一个LLVM后端,但我发现很少有关于它的实现的文献; can someone describe to me how this might be possible? 谁能形容我怎么可能这样呢?

I have no specific experience with LLVM or Erlang. 我没有LLVM或Erlang的特定经验。

But I've implemented such a system, in a programming langauge called PARLANSE. 但是我在一个名为PARLANSE的编程语言中实现了这样一个系统。 Yes, getting the context switches to be cheap is difficult. 是的,让上下文切换变得便宜是很困难的。

More details at this SO answer: https://stackoverflow.com/a/999610/120163 此SO答案的更多细节: https//stackoverflow.com/a/999610/120163

What little knowledge I have of LLVM suggests it may be difficult. 我对LLVM的了解很少,这表明它可能很难。 What you need to generate is context switching code. 您需要生成的是上下文切换代码。 I'm not sure LLVM supports that directly. 我不确定LLVM是否直接支持。 It certainly isn't something that is easy to do when generating pure C code, because the language primitives don't let you get at the machine/thread state very well. 在生成纯C代码时,这当然不容易做,因为语言原语不能让你很好地进入机器/线程状态。

he flip side here is the Clang, in trying to support C++14 features, must surely stumble into "C++ native" threads. 他在这里翻转的是Clang,在试图支持C ++ 14的功能时,肯定会遇到“C ++原生”线程。 There has to be context switching support to enable that, so maybe somebody has is or already has addressed the problem. 必须有上下文切换支持才能实现这一点,所以也许有人已经或已经解决了这个问题。

LLVM isn't directly relevant to implementing this type of system. LLVM与实现此类系统并不直接相关。 There are plenty of frontends for languages with such constructs that lower to LLVM's IR. 对于具有这种结构的语言,有很多前端可以降低到LLVM的IR。

LLVM is just compiler technology to generate native code for a single thread of execution. LLVM只是为单个执行线程生成本机代码的编译器技术。 Implementing context switching, setting up the stack appropriately (cactus stacks or other techniques), and other concerns are primarily the responsibility of the runtime and environment. 实现上下文切换,适当设置堆栈(仙人掌堆栈或其他技术)以及其他问题主要是运行时和环境的责任。

One exception is supporting the synthesis of runtime calls to grow the stack when necessary, and that potentially splitting the stack into non-contiguous regions. 一个例外是支持合成运行时调用以在必要时增长堆栈,并且可能将堆栈拆分为非连续区域。 As indicated in comments, LLVM has some support for this, although it is less well tested. 正如评论中所指出的,LLVM对此有一些支持,尽管它的测试不太好。 However, your frontend can also control the usage of the stack in order to avoid needing any support in LLVM. 但是,您的前端还可以控制堆栈的使用,以避免在LLVM中需要任何支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否有任何编程语言提供命名 function 的返回值的能力? - Do any programming languages provide the ability to name the return value of a function? 是否有任何语言为流程中的“真正”模块化提供支持? - Do any languages provide support for “true” modularity within a process? Perl提供的编译时功能是什么,其他语言没有? - What compile time features does Perl provide that other languages don't? 针对LLVM的功能语言 - Functional languages targeting the LLVM 独立于平台的轻量级编程语言 - Platform Independent, Lightweight Programming Language 是否存在这种语法? 用任何语言? - Does a syntax for this exist? In any language? 除BASIC以外,EOL == EOS是否还有其他任何语言吗? - Does EOL == EOS in any other language besides BASIC? 底层平台是否会影响任何网站或Web应用程序的速度? - Does the underlying platform affect the speedof any web site or web application? 是否有任何编程语言支持定义对原始数据类型的约束? - Does any programming language support defining constraints on primitive data types? SML中的尾递归不会显示任何输出 - Tail recursion in SML does not present any output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM