What is the correct use of process_flag(priority, Level) in Erlang?

纵然是瞬间 提交于 2019-12-08 08:30:19

问题


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?


回答1:


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:

The max priority level is reserved for internal use in the Erlang runtime system, and should not be used by others.



来源:https://stackoverflow.com/questions/13381036/what-is-the-correct-use-of-process-flagpriority-level-in-erlang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!