标签:
转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=20764167&id=4470124
Creating timers using erlang:send_after/3 and erlang:start_timer/3 is much more efficient than
using the timers provided by the timer module. The timer module uses a separate process to manage
the timers, and that process can easily become overloaded if many processes create and cancel timers
frequently (especially when using the SMP emulator).
The functions in the timer module that do not manage timers (such as timer:tc/3 or timer:sleep/1),
do not call the timer-server process and are therefore harmless.
refer: http://www.erlang.org/doc/efficiency_guide/commoncaveats.html#id60818
-----------------------------------------------------------------------------------------------------------------
那么 send_after 和 start_timer 又有什么区别呢,
直接看文档,发现没有什么区别
但是文档一比较,发现一个核心的问题,就在于它们在超时的时候发送的东西不同。
send_after 发送的是个 Msg 消息体,
start_timer 发送的则是 {timeout, TimerRef, Msg} 包含了定时器引用的tuple,
这样接收者就可以区分具体是哪个定时器超时了。
refer: http://www.iteye.com/topic/634815
标签:
原文地址:http://www.cnblogs.com/rsblog/p/4344493.html