<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Mi., 15. Jan. 2020 um 17:41 Uhr schrieb Jesper Louis Andersen <<a href="mailto:jesper.louis.andersen@gmail.com">jesper.louis.andersen@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div style="font-family:arial,helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">On Tue, Jan 7, 2020 at 10:01 AM Andreas Schultz <<a href="mailto:andreas.schultz@travelping.com" target="_blank">andreas.schultz@travelping.com</a>> wrote:</span><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><span style="color:rgb(51,51,51);font-family:Arial,Helvetica,Tahoma,sans-serif;font-size:14px"><br></span></div><div><span style="color:rgb(51,51,51);font-family:Arial,Helvetica,Tahoma,sans-serif;font-size:14px">Could any of the Erlang gurus or ERTS developers comment on the use of home grown mutexes and spinlocks in Erlang in light of that discussion?</span><br></div><div><br clear="all"></div></div></blockquote><div><br></div><div><div style="font-family:arial,helvetica,sans-serif">Not a locking expert in the ERTS, but:</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">The locking API is there to provide a factoring point for the BEAM. The idea is that we have a locking API to use in ERTS which then maps to different implementations as we see fit. This allows us to target both UNIX, Windows, and embedded OS'es at the same time, with a consistent API. But it gets better than that!</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">We can use the factoring point to "plug in" different locking models and try them out. This allows us to choose a locking model which works well. It also allows us to plug in various debugging/correctness checks at compile time. For instance that lock ordering is preserved, if locks are contended on, or if a deadlock happened.</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">That is, the current locking model is sort-of chosen at compile time, based on the capabilities of the underlying system. </div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">All in all, I'm going to claim that the system is not so much "home grown" as it is a sensible wrapper around an underlying system.</div></div></div></div></blockquote><div><br></div><div>I have seen the different underlying implementations for the locking primitives. There are wrappers for Windows and POSIX threads (pthread). But there also seems to be a completely independent implementation of mutexes and spinlocks that does not use the OS or libc provided primitives.</div><div>On Linux that Erlang specific implementation appears to be used by default (that is what I called "home grown"). The pthread version is only used when Erlang is build with valgrind support (or so it seems).</div><div><br></div><div>I was thinking about hacking a build to use only the pthread locking primitives (without the other valdrind overhead) and run some benchmarks.</div><div>However, my hope was that some Erlang expert could shed some light in the locking before I spent the time to do that.</div><div><br></div><div>Anyhow, does anybody have a suggestion for an existing benchmark that could demonstrate differences between locking primitives?</div><div><br></div><div>Andreas</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br></div></div><div><br></div>-- <br><div dir="ltr">J.</div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><p><span style="font-family:verdana,geneva,sans-serif;font-size:10pt">Andreas Schultz<br></span></p>
</div></div>