sends don't block, right?

Shawn Pearce spearce@REDACTED
Wed Feb 25 04:48:21 CET 2004


Ok, colo(u)r me stupid now (borrowed phrase, sorry!):

! doesn't block, right?

If I do something foolish like this:

	never_end() ->
		Pid = spawn(fun() -> receive foo -> ok end),
		do_loop(Pid).

	do_loop(Pid) ->
		Pid ! bar,
		io:format("still going, just like the bunny~n", []),
		do_loop(Pid).

will the parent ever stop because the child's message buffer is full?

Basically, I'm asking if Erlang will let the parent in this case run
the VM out of memory before making the parent freeze.  Clearly one should
never write this code, but I'm trying to setup an async-send for my
serial driver that will "never" block the caller, as apposed to the
blocking send which makes sure the data was delivered to the endpoint
before returning.

The only reason I'm concerned here is the caller could lock up if it
gets blocked and hardware or software flow control breaks down due to
link failure.

With most serial protocols I wouldn't see the need to buffer more than
a few hundred KB of data, and the port driver already has buffers deep
enough to handle that, so in theory, port_command/2 should never block.
I just want to keep from blocking up the application, if the application
so desires.

-- 
Shawn.

  C Code.
  C Code Run.
  Run, Code, RUN!
  	PLEASE!!!!



More information about the erlang-questions mailing list