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

ato*_*3ls 1 erlang scheduling

我想使用process_flag(priority,Level)来设置进程的优先级.我有点困惑的是它应该放在我的代码中,似乎无法找到一个例子.

我能看到的两个选项是:

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

process_flag(priority, max),
register(myprocess, spawn(fun() -> myprocess() end)),
Run Code Online (Sandbox Code Playgroud)

(2)在生成函数后设置函数内的标志:

myprocess() ->
process_flag(priority, max),
%do stuff
Run Code Online (Sandbox Code Playgroud)

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

leg*_*cia 5

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

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

max优先级被保留在Erlang运行系统内部使用,并且应该被别人利用.