gpt4 book ai didi

multithreading - 如何从Erlang中的now()获得微秒

转载 作者:行者123 更新时间:2023-12-03 13:16:36 25 4
gpt4 key购买 nike

我尝试将相应的线程与时间戳(从现在起的微秒函数)进行匹配,就像jill从john [739000]收到介绍性消息,而john从jill [739000]收到回复消息

if
I == true ->
M_pid!{lists:concat([Self_name," received intro message from ", Process_name , "[",erlang:now(),"]"]), self()},
%io:fwrite(I),
whereis(Process_name)!{Self_name, "reply",self()},
friends(Msg, M_pid, State + 1, Self_name);
R == true ->
M_pid!{lists:concat([Self_name," received reply message from ", Process_name , "[",pid_to_list(Process_id),"]"]), self()},
friends(Msg, M_pid, State + 1, Self_name)
end

我试图将 process_idnow()更改为微秒。
我是Erlang的新手。预先谢谢你们!

最佳答案

erlang:now()已过时,不应使用。有两种方法可以获取当前时间(以微秒为单位)

  • os:timestamp()

  • {Mega, Sec, Micro} = os:timestamp(),
    (Mega * 1000000 + Sec) * 1000000 + Micro.
  • os:system_time(microseconds)
  • 关于multithreading - 如何从Erlang中的now()获得微秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62353959/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com