在Erlang中正确使用process_flag(priority,Level)是什么?

时间:2012-11-14 14:44:18

标签: erlang scheduling

我想使用process_flag(priority,Level)来设置进程的优先级。我对我的代码中的位置感到有些困惑,似乎无法找到一个例子。

我能看到的两个选项是:

(1)在产生过程之前设置标志:

process_flag(priority, max),
register(myprocess, spawn(fun() -> myprocess() end)),

(2)在生成函数后设置该函数:

myprocess() ->
process_flag(priority, max),
%do stuff

此外,如果选项1是正确的,我是否需要在生成其他进程之前将标志重置为normal

1 个答案:

答案 0 :(得分:5)

选项2是正确的。正如documentation所说,process_flag/2“为调用此函数的进程设置了某些标志”。我认为任何进程标志都不会继承到生成的进程。

文档还建议不要使用max优先级:

  

max优先级保留供Erlang运行时系统内部使用,其他人不应