BIFs use with care

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

BIFs use with care

nato
I recently saw an ESL video advising that one should
use Erlang BIFs with care... it was a bit of an aside, so
I was wondering if someone could could elaborate
on this. It seemed to suggest that BIFs (the ones written
in C?) could block/cause problems ...

After many books, this is the first I've heard of it and would
love a rundown on things to watch out for regarding BIFs.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: BIFs use with care

Mikael Pettersson-5
On Tue, Oct 17, 2017 at 4:47 PM, nato <[hidden email]> wrote:
I recently saw an ESL video advising that one should
use Erlang BIFs with care... it was a bit of an aside, so
I was wondering if someone could could elaborate
on this. It seemed to suggest that BIFs (the ones written
in C?) could block/cause problems ...

Presumably they were referring to preemption.

BEAM code is preemptive by design, meaning that the VM can suspend a process and schedule another at almost any instant.  (I'm simplifying, but that's the essence of it.)  BIFs, being C code inside the VM, are not preemptive by default: they have to be written in a special and potentially slower way to make them preemptive.  This means that for large inputs (e.g. long lists or binaries, or deep terms) a broken BIF may block its scheduler until it's finished.  That's potentially very bad, depending on your application.

Most such bugs should be fixed by now (they were more common 5+ years ago), but it's possible some remain.  I wouldn't avoid BIFs unless I knew for a fact that the VM I was using had such a bug in it.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions