<div dir="ltr">Sorry, to be clearer, that should have read "<span style="font-size:12.800000190734863px">when run in a separate thread in the NIF using enif_thread_create(), the API call succeeds under R18 on El Capitan, fails under R19 on El Capitan, and fails under R18 and R19 on Sierra".</span></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 18, 2017 at 7:52 AM, Igor Clark <span dir="ltr"><<a href="mailto:igor.clark@gmail.com" target="_blank">igor.clark@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Thanks Paul and Daniel,<br>
<br>
Just tested this: the exact same thing happens with threads as
without. The API call succeeds when run in a separate thread in the
minimal C program using pthread_create(), on both El Capitan and
Sierra; when run in a separate thread in the NIF using
enif_thread_create(), the API call succeeds under R18 on El Capitan
and fails under R19.<br>
<br>
(My NIF code hasn't been explicitly creating or using any threads at
all until now, if that makes any difference.)<br>
<br>
Does that give any further clues?<br>
<br>
Cheers,<br>
Igor<div><div class="h5"><br>
<br>
<div class="m_2753930781096260743moz-cite-prefix">On 18/04/2017 03:47, Daniel Goertzen
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Following Paul's idea, what happens in both the NIF
and your minimal C program if you first launch a new thread and
call the API from there?</div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Mon, Apr 17, 2017 at 5:52 PM Fisher, Paul <<a href="mailto:pfisher@alertlogic.com" target="_blank">pfisher@alertlogic.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div>
<div id="m_2753930781096260743m_-2395972316349742208x_compose-container" style="direction:ltr">
<span><span></span></span>
<div>
<div style="direction:ltr">Complete wild guess, but is
there a difference in nif initialization running off
the main thread in non-working version? This would
be a problem for some low-level Mach related things.
Not near laptop to look through the code to see if
that changed.</div>
<div><br>
</div>
<div><br>
</div>
<div class="m_2753930781096260743m_-2395972316349742208x_acompli_signature">Get
<a href="https://aka.ms/o0ukef" target="_blank">Outlook
for iOS</a></div>
</div>
</div>
<hr style="display:inline-block;width:98%">
<div id="m_2753930781096260743m_-2395972316349742208x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri,
sans-serif"><b>From:</b> <a href="mailto:erlang-questions-bounces@erlang.org" target="_blank">erlang-questions-bounces@<wbr>erlang.org</a>
<<a href="mailto:erlang-questions-bounces@erlang.org" target="_blank">erlang-questions-bounces@<wbr>erlang.org</a>>
on behalf of Igor Clark <<a href="mailto:igor.clark@gmail.com" target="_blank">igor.clark@gmail.com</a>><br>
<b>Sent:</b> Monday, April 17, 2017 4:38:11 PM<br>
<b>To:</b> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<b>Subject:</b> [erlang-questions] NIF+device problem
moving R18->R19 / Mac 10.11->10.12</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt">
</span></font></div>
<div><font size="2"><span style="font-size:10pt">
<div class="m_2753930781096260743m_-2395972316349742208PlainText">Hi all,<br>
<br>
I'm having problems updating a NIF to work correctly
with R19 and/or <br>
MacOS Sierra (10.12). The NIF uses Mac OS C API calls
to talk to some <br>
hardware. It's been working just fine with R18 on El
Capitan, but it <br>
fails in a manner I don't understand when I trying to
run it on R19 or <br>
Sierra. I'm pretty baffled as to what's going on, and
wonder if any of <br>
the following might ring bells or set off a
spider-sense for anyone here?<br>
<br>
- The code continues to work 100% as expected on R18 /
Mac OS El Capitan <br>
(10.11), as it has for the last year or so.<br>
<br>
- On R19 on El Capitan, 99% of the C code works as
before, but one <br>
particular MacOS C API call fails unexpectedly. It
doesn't crash or <br>
cause errors directly, but it returns null instead of
a valid value as <br>
before. There are no build errors or warnings. (I'm
using 'pc' plugin <br>
version 1.5.0 with rebar3). Other MacOS API calls
talking to the same <br>
hardware work as expected, sending correct commands,
getting the <br>
hardware to carry out operations as expected and
returning expected <br>
values, without any problems.<br>
<br>
- On both R18 & R19 on Sierra, exactly the same
problem occurs as above <br>
in R19 on El Capitan.<br>
<br>
- If I make the failing/null-returning OS API call in
a plain, <br>
simple-as-possible C file compiled with gcc (Apple
LLVM/clang), it works <br>
as expected, *on both OS versions*.<br>
<br>
- If I paste that same simple-as-possible C code
verbatim into the NIF, <br>
as the first line in the load() function, and run it
on R18/El Capitan, <br>
it continues to work as expected.<br>
<br>
- If I then try to run that identical pasted-verbatim
NIF code with no <br>
changes on R18/Sierra or on R19 & either OS
version, this one particular <br>
function call fails, as above.<br>
<br>
I realise it could be many things, and my initial
thought was that it <br>
must be the OS change or even the hardware failing -
but the hardware <br>
and C API call continue to work just fine on both OS
versions when the <br>
NIF stuff is taken out of the picture, and on El
Capitan, the <br>
previously-not-happening problem reliably (and only)
starts happening <br>
when I switch from R18 to R19.<br>
<br>
Did anything change between R18 and R19 that might
somehow make some, <br>
but not all, external C function calls fail on El
Capitan/clang 8.0.0? <br>
And could that be something that also makes the same
thing happen on <br>
both R18 and R19 under Sierra/clang 8.1.0? Could it
perhaps be something <br>
do with the port compiler & LD/CXX flags?<br>
<br>
Any ideas as to where else I could look to try to
track this down, or <br>
what might be causing this?<br>
<br>
(BTW, I'm using homebrew erlang, and I've tried all
the above with <br>
versions 18.1, 18.3, 19.0.2 and 19.3 on both OS
versions. The gcc/clang <br>
version on El Capitan is from Xcode 8.1, "Apple LLVM
version 8.0.0 <br>
(clang-800.0.42.1)". On Sierra it's from Xcode 8.3.1,
"Apple LLVM <br>
version 8.1.0 (clang-802.0.41)" - but as above, the
plain/non-NIF C code <br>
works perfectly and identically on both versions.)<br>
<br>
Thanks very much,<br>
Igor<br>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
</div>
</span></font></div>
<div><font size="2"><span style="font-size:10pt">
<div class="m_2753930781096260743m_-2395972316349742208PlainText"><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__erlang.org_mailman_listinfo_erlang-2Dquestions&d=DwICAg&c=L_h2OePR2UWWefmqrezxOsP9Uqw55rRfX5bRtw9S4KY&r=PevFox_7LK44ZV_jlS5jRM2WItKtsHV4zN_CrbdT2aM&m=VYIypVbNEBkrDndUBzmlPhRtnzb4ZWIKbuytw-ZNFsQ&s=jm04c9Iw58-WmaHYaGFw-a9XQ3sFl2wqkf7RhdBDC6E&e=" target="_blank">https://urldefense.proofpoint.<wbr>com/v2/url?u=http-3A__erlang.<wbr>org_mailman_listinfo_erlang-<wbr>2Dquestions&d=DwICAg&c=L_<wbr>h2OePR2UWWefmqrezxOsP9Uqw55rRf<wbr>X5bRtw9S4KY&r=PevFox_7LK44ZV_<wbr>jlS5jRM2WItKtsHV4zN_CrbdT2aM&<wbr>m=<wbr>VYIypVbNEBkrDndUBzmlPhRtnzb4ZW<wbr>IKbuytw-ZNFsQ&s=jm04c9Iw58-<wbr>WmaHYaGFw-<wbr>a9XQ3sFl2wqkf7RhdBDC6E&e=</a>
<br>
</div>
</span></font>Confidentiality Notice | This email and any
included attachments may be privileged, confidential and/or
otherwise protected from disclosure. Access to this email by
anyone other than the intended recipient is unauthorized. If
you believe you have received this email in error, please
contact the sender immediately and delete all copies. If you
are not the intended recipient, you are notified that
disclosing, copying, distributing or taking any action in
reliance on the contents of this information is strictly
prohibited.
</div>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
</blockquote>
</div>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br></div>