Are Rprintf and REprintf thread-safe?

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

Are Rprintf and REprintf thread-safe?

Winston Chang
Is it safe to call Rprintf and REprintf from a background thread? I'm
working on a package that makes calls to fprintf(stderr, ...) on a
background thread when errors happen, but when I run R CMD check, it
says:

  Compiled code should not call entry points which might terminate R nor
  write to stdout/stderr instead of to the console, nor the system RNG.

Is it safe to replace these calls with REprintf()?

-Winston

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Are Rprintf and REprintf thread-safe?

luke-tierney
On Tue, 21 Nov 2017, Winston Chang wrote:

> Is it safe to call Rprintf and REprintf from a background thread? I'm
> working on a package that makes calls to fprintf(stderr, ...) on a
> background thread when errors happen, but when I run R CMD check, it
> says:
>
>  Compiled code should not call entry points which might terminate R nor
>  write to stdout/stderr instead of to the console, nor the system RNG.
>
> Is it safe to replace these calls with REprintf()?

Only if you enjoy race conditions or segfaults.

Rprintf and REprintf are not thread-safe.

Best,

luke


>
> -Winston
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Are Rprintf and REprintf thread-safe?

Winston Chang
Thanks - I'll find another way to send messages to the main thread for printing.

-Winston

On Tue, Nov 21, 2017 at 12:42 PM,  <[hidden email]> wrote:

> On Tue, 21 Nov 2017, Winston Chang wrote:
>
>> Is it safe to call Rprintf and REprintf from a background thread? I'm
>> working on a package that makes calls to fprintf(stderr, ...) on a
>> background thread when errors happen, but when I run R CMD check, it
>> says:
>>
>>  Compiled code should not call entry points which might terminate R nor
>>  write to stdout/stderr instead of to the console, nor the system RNG.
>>
>> Is it safe to replace these calls with REprintf()?
>
>
> Only if you enjoy race conditions or segfaults.
>
> Rprintf and REprintf are not thread-safe.
>
> Best,
>
> luke
>
>
>>
>> -Winston
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> --
> Luke Tierney
> Ralph E. Wareham Professor of Mathematical Sciences
> University of Iowa                  Phone:             319-335-3386
> Department of Statistics and        Fax:               319-335-3017
>    Actuarial Science
> 241 Schaeffer Hall                  email:   [hidden email]
> Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Are Rprintf and REprintf thread-safe?

Martin Morgan-3
On 11/21/2017 04:12 PM, Winston Chang wrote:
> Thanks - I'll find another way to send messages to the main thread for printing.

The CRAN synchronicity and Bioconductor BiocParallel packages provide
inter-process locks that you could use to surround writes (instead of
sending message to the main thread), also easy enough to incorporate at
the C level using the BH package as source for relevant boost header.

Martin

>
> -Winston
>
> On Tue, Nov 21, 2017 at 12:42 PM,  <[hidden email]> wrote:
>> On Tue, 21 Nov 2017, Winston Chang wrote:
>>
>>> Is it safe to call Rprintf and REprintf from a background thread? I'm
>>> working on a package that makes calls to fprintf(stderr, ...) on a
>>> background thread when errors happen, but when I run R CMD check, it
>>> says:
>>>
>>>   Compiled code should not call entry points which might terminate R nor
>>>   write to stdout/stderr instead of to the console, nor the system RNG.
>>>
>>> Is it safe to replace these calls with REprintf()?
>>
>>
>> Only if you enjoy race conditions or segfaults.
>>
>> Rprintf and REprintf are not thread-safe.
>>
>> Best,
>>
>> luke
>>
>>
>>>
>>> -Winston
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> --
>> Luke Tierney
>> Ralph E. Wareham Professor of Mathematical Sciences
>> University of Iowa                  Phone:             319-335-3386
>> Department of Statistics and        Fax:               319-335-3017
>>     Actuarial Science
>> 241 Schaeffer Hall                  email:   [hidden email]
>> Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


This email message may contain legally privileged and/or...{{dropped:2}}

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel