Erl Ports and Threads

Per Hedeland <>
Thu Dec 16 11:10:30 CET 2004

>On Thu, Dec 16, 2004 at 03:37:34PM +0600, Casper wrote:
>> Hi Klacke,
>> Thanks for the response.
>> Here I am not talking about simultaneous write() operations on a socket/pipe
>> from the multiple external program. I am talking about multiple threads in
>> one program.
>I know, that's what you wrote.
>> Is single write() call, atomic or not?

Actually this isn't entirely true - when different processes write to
the same pipe, their writes are guaranteed (on a standards-compliant
Unix:-) to be atomic if they are "small enough" - from a decent
pathconf(2) man page:

             The maximum number of bytes which will be written atomically to a

(The number is typically 4096 or so.) Whether this is still true for
different threads in a process writing to the same pipe I don't know,
but I would expect so (might be implementation-dependant though). And of
course relying on the undocumented fact that the port communication
channel *is* a pipe, and not e.g. a local socket which doesn't have such
guarantees, isn't a very good idea.

For all practical purposes, I agree with Klacke's answer.:-)


More information about the erlang-questions mailing list