raw file write from non-owning thread
Reto Kramer
kramer@REDACTED
Mon Aug 7 21:14:21 CEST 2006
I ran into a puzzle writing to a raw file from a process different
from the one that opened the file (owns it). Below the first
"raw:run" is without the raw option. Everything is fine. When I add
the raw option though, the process that opened the file (here the
shell) receives a message from the port when the write is performed
from another process (see flush). Also note that the writing function
(process) w/2 did not run to completion (the "done writing" string is
not printed).
Can someone help me understand how I can write to a raw file from a
process other than the one that opened the file?
Thanks,
- Reto
%% without raw
1> raw:run("test.log").
done writing.
<0.34.0>
%% with raw
1> raw:run("test.log").
<0.33.0>
2> flush().
Shell got {#Port<0.96>,{data,[3,0,0,0,0,0,0,0,1]}}
ok
-module(raw).
-export([run/1, w/2]).
run(Filename) ->
{ok,H} = file:open(Filename, [append, binary, raw]),
proc_lib:spawn_link(?MODULE, w, [H, <<1>>]).
w(H, Bin) ->
file:write(H, Bin),
io:format("done writing.~n", []).
#
More information about the erlang-questions
mailing list