Multithreaded Drivers

Raimo Niskanen <>
Fri Aug 3 10:11:08 CEST 2001

And here is some more info on the same subject that I think is of public

/ Raimo Niskanen, Erlang/OTP, Ericsson UAB.


Sean Hinde wrote:
> Raimo,
> Another question.. Has anyone ever experimented with avoiding the copying of
> data between the erlang thread and the worker thread? Perhaps by using a
> mutex type arrangement, or even by simply ensuring that the erlang side
> doesn't send any more data to overwrite the buffer until it is given
> permission to do so.

Yes, I have. I am rewriting efile_drv to store file data in the port
queue. Then data is accessed both from the main thread and from the
worker threads. Access is protected by a mutex in the port data
structure. So far it seems to work fine.

Beware of the danger the port being closed at any time, meaning that the
port data structure and hence the mutex can be freed and perhaps
overwritten at any time, so a worker thread might get the mutex
corrupted at any time.

I happen to avoid this since the port will not be closed while there is
data in the port queue. A workaround for other cases might be to store a
byte in the port queue while there are unfinished async requests.

/ Raimo

More information about the erlang-questions mailing list