[erlang-questions] Subtle behaviour of Erlang scheduler

Jordan Wilberding <>
Thu May 24 14:57:16 CEST 2007


I am definitely not a guru, but I will take my best guess at it.

My guess that it has something to do with using both 
process_flag(priority, high) and having a timeout of zero in the count 
receive loop. If you comment out process_flag(priority, high) in proc2/0 
or you change after 0 to after 1 in count/1 the program will work.

If you look at top in linux or task manager in windows, the program runs 
at nearly 100%. My guess is the proc2 is running with such a high 
priority that it is hitting that after 0 every time and not giving a 
chance for the proc2 ! x and proc3 ! x to be executed.

Again, I am not a guru, but this is my best guess based on the 
obvservations I saw.

Thanks!
Jordan Wilberding

KatolaZ wrote:
> Dear Erlang Gurus,
>
> we have tested the priority system of the processes and we are 
> experiencing a very strange behaviour.
>
> Take a look at the simple code attached: if you run "test:test()" from
> the shell, the system hangs and "proc2" never ends blocking also
> "proc1" and the shell. We think that this is due to the fact that
> "proc2" hasn't any synchronization point, i.e. send or receive
> messages, etc. In any case, this is quite strange since also "proc1"
> has priority set to "high", so sooner or later, it should be selected
> to be scheduled.
>
> Now kill the shell (with CTRL+C, you don't have any other option!),
> uncomment the "timer:sleep(1)" statement in proc2, recompile and
> everything seems to work fine: "proc2" and "proc3" exit, and the value
> reached by the counter proves that proc2 really runs with a higher
> priority than proc3.
>
> Well, now, don't exit from the shell, comment again the
> "timer:sleep(1)" line, compile the code with "c(test)", and run it
> again. Well, now it works!!! But if you (once again) exit the shell,
> run "erl" again and launch "test:test()" once more.... it blocks!!!
>
> What's behind this strange behaviour? An undocumented feature? A bug
> in scheduler initialization? Too many beers before sitting down for
> coding :-))) ???
>
> All the best,
> --Enzo and Corrado
>
>   




More information about the erlang-questions mailing list