Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Erlang 二郎';s计时器:运行时/4次崩溃后应用\u_Erlang - Fatal编程技术网

Erlang 二郎';s计时器:运行时/4次崩溃后应用\u

Erlang 二郎';s计时器:运行时/4次崩溃后应用\u,erlang,Erlang,我在引用 为什么定时器模块加载不正确?定时器模块是stdlib的一部分,它是自动启动的,但启动新VM不需要定时器模块 验证文件timer.beam是否存在于???/erlX.Y/lib/stdlib ZZZ\ebin目录中 [编辑] 我已经在我的笔记本电脑上测试了您的代码,唯一的区别是我将模块名称从counter改为count(我的“垃圾”目录中已经有一个计数器模块)。它可以正常工作,但不会产生错误: 1> c(count). {ok,count} 2> count:start().

我在引用


为什么定时器模块加载不正确?

定时器模块是stdlib的一部分,它是自动启动的,但启动新VM不需要定时器模块

验证文件timer.beam是否存在于???/erlX.Y/lib/stdlib ZZZ\ebin目录中

[编辑] 我已经在我的笔记本电脑上测试了您的代码,唯一的区别是我将模块名称从counter改为count(我的“垃圾”目录中已经有一个计数器模块)。它可以正常工作,但不会产生错误:

1> c(count).
{ok,count}
2> count:start().
<0.40.0>
3> count:add(pid(0,40,0),3).
3
4> count:add(pid(0,40,0),5).
8
例如:

1> c(count).
{ok,count}
2> P = count:start().
<0.63.0>
3> {ok,TRef} = timer:apply_interval(2000,count,get,[P]).
{ok,{interval,#Ref<0.0.4.100>}}
4> timer <0.63.0> value is 110
timer <0.63.0> value is 130
timer <0.63.0> value is 150
timer <0.63.0> value is 170
timer <0.63.0> value is 190
timer <0.63.0> value is 210
timer <0.63.0> value is 230
timer <0.63.0> value is 250
count:resolve(P).
resolve
5> timer <0.63.0> value is 10
timer <0.63.0> value is 30
timer <0.63.0> value is 50
timer <0.63.0> value is 70
timer <0.63.0> value is 90
timer <0.63.0> value is 110
timer <0.63.0> value is 130
timer <0.63.0> value is 150
timer <0.63.0> value is 170
count:stop(P).
terminate
6> timer:cancel(TRef).
{ok,cancel}
7>
1>c(计数)。
{好的,伯爵}
2> P=计数:开始()。
3> {ok,TRef}=timer:apply_interval(2000,count,get,[P])。
{好,{interval,#Ref}}
4> 计时器值为110
计时器值为130
计时器值为150
计时器值为170
计时器值为190
计时器值为210
计时器值为230
计时器值为250
计数:解析(P)。
决定
5> 计时器值为10
计时器值为30
计时器值为50
计时器值为70
计时器值为90
计时器值为110
计时器值为130
计时器值为150
计时器值为170
计数:停止(P)。
终止
6> 计时器:取消(TRef)。
{好的,取消}
7>

文档明确指出函数应该是原子。你在传递一种乐趣。将“fun add/2”更改为简单的“add”,并确保已导出add/2。

我已经测试了这段代码,它可以正常工作。所以我相信安装中有问题。更正,它不工作但不会产生错误。是的,如果参数是假的,它似乎会自动失败。我检查了计时器模块的源代码,只检查了时间(必须是整数>=0),但{M,F,a}未经检查存储在ets中,等待执行,在
捕获繁殖(M,F,a)
中及时执行,因此它会以静默方式失败。这确实有效,谢谢!我的当前目录中有一个timer.beam,它干扰了我。什么是
code:which(timer)
返回的?它应该显示
定时器
模块是从
stdlib
应用程序加载的。
-module(count).
-compile(export_all).

counter(State) ->
  receive
    {add, Number} ->
      NewNumber = State+Number,
      timer:apply_after(1000, ?MODULE, add, [self(), 10]),
      counter(NewNumber);
    resolve ->
          counter(0);
    {From, get} ->
          From ! {self(), State},
          counter(State);
    terminate ->
       ok
   end.

add(Pid, Number) ->
  Pid ! {add, Number}.

resolve(Pid) ->
  Pid ! resolve.

get(Pid) -> 
  Pid ! {self(),get},
  receive
    {P,V} -> 
      io:format("timer ~p value is ~p~n",[P,V]),
      V
  after 3000 ->
    {error,"not responding"}
  end.

stop(Pid) ->
  Pid ! terminate.

start() ->
  Pid = spawn(?MODULE, counter, [0]),
  timer:apply_after(1000, ?MODULE, add, [Pid, 10]),
  Pid.
1> c(count).
{ok,count}
2> P = count:start().
<0.63.0>
3> {ok,TRef} = timer:apply_interval(2000,count,get,[P]).
{ok,{interval,#Ref<0.0.4.100>}}
4> timer <0.63.0> value is 110
timer <0.63.0> value is 130
timer <0.63.0> value is 150
timer <0.63.0> value is 170
timer <0.63.0> value is 190
timer <0.63.0> value is 210
timer <0.63.0> value is 230
timer <0.63.0> value is 250
count:resolve(P).
resolve
5> timer <0.63.0> value is 10
timer <0.63.0> value is 30
timer <0.63.0> value is 50
timer <0.63.0> value is 70
timer <0.63.0> value is 90
timer <0.63.0> value is 110
timer <0.63.0> value is 130
timer <0.63.0> value is 150
timer <0.63.0> value is 170
count:stop(P).
terminate
6> timer:cancel(TRef).
{ok,cancel}
7>