问题描述
我想使用process_flag(priority,Level)来设置进程的优先级。我有点困惑,在我的代码中应该去哪里,似乎找不到一个例子。
我看到的两个选项是: p>
(1)在产生过程之前设置标志:
process_flag priority,max),
注册(myprocess,spawn(fun() - > myprocess()end)),
(2)在函数生成之后设置标志:
myprocess() - >
process_flag(priority,max),
%do stuff
另外,如果选项1是正确的,我需要在产生其他进程之前将标志重置为正常
选项2是正确的。 说, process_flag / 2
为调用此函数的进程设置某些标志。我不认为任何进程标志都被继承为生成的进程。
文档还建议不要使用 max
优先级:
I want to use the process_flag(priority, Level) to set the priority of a process. I am a little confused as to where it should go in my code and can't seem to find an example.
The two options that I can see are:
(1) Set the flag before spawning the process:
process_flag(priority, max),
register(myprocess, spawn(fun() -> myprocess() end)),
(2) Set the flag within the function after it has been spawned:
myprocess() ->
process_flag(priority, max),
%do stuff
Also, if option 1 is correct, do I need to reset the flag to normal
before spawning other processes?
Option 2 is the correct one. As the documentation says, process_flag/2
"sets certain flags for the process which calls this function". I don't think any of the process flags are inherited to spawned processes.
The documentation also suggests not using the max
priority level:
这篇关于在Erlang中process_flag(priority,Level)的正确使用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!