[erlang-questions] erlang *****

Andras Georgy Bekes bekesa@REDACTED
Tue Mar 18 15:22:26 CET 2008


> I think a pattern match 
> is an atomic operation in the VM, I mean, the scheduler won't switch
> to another process in the middle of a pattern match.
Tested and seems true.

Check matchtest:test(50000).

So you can easily hang the whole Erlang VM by carefully building a huge 
pattern match :-(
it doesn't even need much memory to do it.

	Georgy
-------------- next part --------------
-module(matchtest).

-export([test/1]).

tickloop()->
    io:format("Tick\n",[]),
    receive
	stop->
	    ok
    after 500 ->
	    tickloop()
    end.

test(N)->
    Tick=spawn_link(fun()->
			    tickloop()
		    end),
    
    AList=lists:duplicate(N,lists:seq(1,N)),
    BList=lists:duplicate(N,lists:seq(1,N)),
  
    io:format("Waiting for a while to see if tick works...\n",[]),
    receive
    after 3000 -> ok
    end,
    io:format("Matching...\n",[]),
    AList=BList,
    
    Tick ! stop,
    ok.


More information about the erlang-questions mailing list