Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  pause a process?

Skully
Posted: Fri May 13, 2011 9:02 am Reply with quote
Joined: 21 May 2007 Posts: 8
Hi,

i have processes which execute some code.
I would like to be able to pause each process and let them continue their work if needed.
A bonus would be to give each process a time-interval, for that time the process can execute something.

Some interesting things ive found in http://ftp.csd.uu.se/papers/masters-theses/0178-ekstrom.pdf but thats without the code.

In Java for example i would use something like thread.sleep(). I have seen some suspend method for erlang but with a warning to only use it for debugging.

Any tipps how to accomplish something like that in erlang?
View user's profile Send private message
flodis
Posted: Fri May 13, 2011 12:40 pm Reply with quote
User Joined: 09 Jul 2008 Posts: 27
Check out the sleep function in the timer module, it probably does what you want.

http://www.erlang.org/doc/man/timer.html#sleep-1

However, it sounds that you need to enter a receive loop for your processes that will continue work when a message is received.

I am not 100% sure what you want, but you might want to consider this:
Each process do work in a loop
Before entering the loop, you take the start time
In the beginning of each loop iteration, you mesure if X time has passed (check timer:now_diff/2)
If time X has passed, you enter a receive loop that will wait until a message to proceed is received. (Then you take start time again and repeat the this process)
View user's profile Send private message
anmolsingh008
Posted: Fri Jul 08, 2011 5:59 am Reply with quote
Joined: 05 Jul 2011 Posts: 2
Hi

You can use erlang:send_after/3 to send a signal to your paused process to resume.

Something like below:

start()->
Pid = spawn(?MODUKE, process, []),
erlang:send_after(5000, Pid, resume).

process()->
receive
Anything -> resume
after 10000 -> timeout
end.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum