<div dir="ltr">After testing locally with clang, it seems the problem actually was that there were different classes inheriting from RcppParallel::Worker in different cpp files, but they all had the same names and the same constructors, yet different logic. There were no compilation warnings, but apparently clang doesn't isolate each class to the file where it is declared+defined, even if it doesn't appear in any header.<div><br></div><div>Thanks,</div><div>Alexis.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 20, 2018 at 4:22 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
On 20 January 2018 at 15:05, Alexis Sarda wrote:<br>
| The idea is indeed to avoid copying memory. I thought that doing something<br>
| like the following would allow me to read the values created in R from<br>
| within the threads:<br>
|<br>
| Rcpp::NumericVector vec(vector_from_R);<br>
| std::vector<RcppParallel::<wbr>RVector<double>> series;<br>
| series.push_back(RcppParallel:<wbr>:RVector<double>(vec));<br>
| // then in the threads:<br>
| double val = series[index_for_this_thread][<wbr>0];<br>
|<br>
| The data created on the R side is never modified by these functions, just<br>
| read. It is possible for different threads to read the same memory, but I<br>
| thought reading was not subject to race conditions.<br>
|<br>
| The segfaults are very consistent, every OSX build fails with the same<br>
| error at the same point. The fact that it happens with clang++ but not with<br>
| gcc++ is puzzling to me.<br>
|<br>
| The Rcpp::List may contain a lot of NumericVector or NumetricMatrix series,<br>
| so I would rather not copy all of them.<br>
<br>
</span>But the RcppParallel documentation is pretty clear on "do not touch R memory<br>
from multiple threads".<br>
<div class="HOEnZb"><div class="h5"><br>
Dirk<br>
<br>
--<br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</div></div></blockquote></div><br></div>