erlang中的spawn函数

spawn(Fun) -> pid()

参数类型:

Fun = function()    %% 参数为空的函数
返回类型: 进程Pid
说明:生成一个由Fun函数启动的、参数为空的新进程,并返回进程的Pid。


spawn(Node, Fun) -> pid()

参数类型:

Node = node()      %% 节点
Fun = function()   %% 参数为空的函数

返回类型:进程Pid
说明:生成一个由在Node节点上,由Fun函数启动的、参数为空的新进程,并返回进程的Pid。


spawn(Module, Function, Args) -> pid()

参数类型:

Module = module()  %% 模块名
Function = atom()  %% 原子函数名
Args = [term()]    %% 参数列表

返回类型:进程Pid
说明:生成一个由Module:Function函数启动的、参数为Args列表的新进程,并返回进程的Pid。

新的进程会被放入系统的调度队列之中,延后创建。


error_handler:undefined_function(Module, Function, Args) is evaluated by the new process if Module:Function/Aritydoes not exist (where Arity is the length of Args). The error handler can be redefined (see process_flag/2). If error_handler is undefined, or the user has redefined the default error_handler its replacement is undefined, a failure with the reason undef will occur.

> spawn(speed, regulator, [high_speed, thin_cut]).
<0.13.1>

spawn(Node, Module, Function, Args) -> pid()

Types:

Node = node()
Module = module()
Function = atom()
Args = [term()]

返回类型:进程Pid
说明:生成一个在Node节点上,由Module:Function启动的、参数为Args列表的新进程,并返回进程的Pid。
如果Node不存在,会返回一个没用的pid。其他情况和spawn/3一样。

hzhsan注:函数不等于函数的返回值。参数是表达式,如果这个表达式的结果应该是个函数,那么就不能是函数的返回值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值