Thread-safe R functions

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

Thread-safe R functions

Wang Jiefei
Hi,

I am curious about whether there exist thread-safe functions in
`Rinternals.h`.  I know that R is single-threaded designed, but for the
simple and straightforward functions like `DATAPTR` and `INTEGER_GET_REGION`,
are these functions safe to call in a multi-thread environment?

Best,
Jiefei

        [[alternative HTML version deleted]]

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

Re: [External] Thread-safe R functions

luke-tierney
You should assume that NO functions or macros in the R API are
thread-safe.  If some happen to be now, on some platforms, they are
not guaranteed to be in the future. Even if you use a global lock you
need to keep in mind that any function in the R API can signal an
error and execute a longjmp, so you need to make sure you have set a
top level context in your thread.

Best,

luke

On Sun, 13 Sep 2020, Jiefei Wang wrote:

> Hi,
>
> I am curious about whether there exist thread-safe functions in
> `Rinternals.h`.  I know that R is single-threaded designed, but for the
> simple and straightforward functions like `DATAPTR` and `INTEGER_GET_REGION`,
> are these functions safe to call in a multi-thread environment?
>
> Best,
> Jiefei
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [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: [External] Thread-safe R functions

Gabriel Becker-2
Jiefei,

Beyond the general response that Luke gave, to be a bit more specific to
what you said, DATAPTR and INTEGER_GET_REGION involve ALTREP method
execution (for ALTREP objects, obviously) so even they are not as simple
and straightforward as they were a couple years ago. They should not (any
longer) be thought of as being guaranteed to be essentially bare metal data
retrieval from memory.

Best,
~G

On Sun, Sep 13, 2020 at 6:49 AM <[hidden email]> wrote:

> You should assume that NO functions or macros in the R API are
> thread-safe.  If some happen to be now, on some platforms, they are
> not guaranteed to be in the future. Even if you use a global lock you
> need to keep in mind that any function in the R API can signal an
> error and execute a longjmp, so you need to make sure you have set a
> top level context in your thread.
>
> Best,
>
> luke
>
> On Sun, 13 Sep 2020, Jiefei Wang wrote:
>
> > Hi,
> >
> > I am curious about whether there exist thread-safe functions in
> > `Rinternals.h`.  I know that R is single-threaded designed, but for the
> > simple and straightforward functions like `DATAPTR` and
> `INTEGER_GET_REGION`,
> > are these functions safe to call in a multi-thread environment?

>
> > Best,
> > Jiefei
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [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
>

        [[alternative HTML version deleted]]

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

Re: [External] Thread-safe R functions

Wang Jiefei
Thanks, Gabriel and Luke. That is exactly what I would like to know. I
appreciate your suggestions.

Best,
Jiefei

On Mon, Sep 14, 2020 at 6:08 AM Gabriel Becker <[hidden email]>
wrote:

> Jiefei,
>
> Beyond the general response that Luke gave, to be a bit more specific to
> what you said, DATAPTR and INTEGER_GET_REGION involve ALTREP method
> execution (for ALTREP objects, obviously) so even they are not as simple
> and straightforward as they were a couple years ago. They should not (any
> longer) be thought of as being guaranteed to be essentially bare metal data
> retrieval from memory.
>
> Best,
> ~G
>
> On Sun, Sep 13, 2020 at 6:49 AM <[hidden email]> wrote:
>
>> You should assume that NO functions or macros in the R API are
>> thread-safe.  If some happen to be now, on some platforms, they are
>> not guaranteed to be in the future. Even if you use a global lock you
>> need to keep in mind that any function in the R API can signal an
>> error and execute a longjmp, so you need to make sure you have set a
>> top level context in your thread.
>>
>> Best,
>>
>> luke
>>
>> On Sun, 13 Sep 2020, Jiefei Wang wrote:
>>
>> > Hi,
>> >
>> > I am curious about whether there exist thread-safe functions in
>> > `Rinternals.h`.  I know that R is single-threaded designed, but for the
>> > simple and straightforward functions like `DATAPTR` and
>> `INTEGER_GET_REGION`,
>> > are these functions safe to call in a multi-thread environment?
>
> >
>> > Best,
>> > Jiefei
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > [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
>>
>

        [[alternative HTML version deleted]]

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