enif_send() thread safety

Alceste Scalas alceste@REDACTED
Wed Nov 24 16:50:18 CET 2010

 On Wed, 24 Nov 2010 15:04:36 +0100, Paul Guyot <pguyot@REDACTED> 
>> The enif_thread_create() and enif_send() pair Alceste wrote looks 
>> very
>> interesting, though I also guess it's a bit too complicated for a 
>> random
>> number generator.
> Please note that using enif_send() for this purpose only works with
> SMP emulators.

 Uh, you're right.  I must confess that I completely missed the
 following paragraph (from the docs):

   unsigned enif_send(...)
     This function is only thread-safe when the emulator with SMP
     support is used. It can only be used in a non-SMP emulator
     from a NIF-calling thread.

 Maybe it's due to the fact that, last time I checked, the
 non-SMP emulator does not lock its internal data structures,
 since just one thread is expected to access them.

 From previous discussions in this ML, I've seen that other
 developers are using enif_send() from separate NIF threads.
 See, for example:


 If people start using this (very convenient) feature, we could
 see a whole new class of Erlang modules which depend on the
 type of emulator being used...  And it may be quite confusing,

 Alceste Scalas <alceste@REDACTED>

More information about the erlang-questions mailing list