Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-15841

[R] Implement SafeCallIntoR to safely call the R API from another thread

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 8.0.0
    • R

    Description

      In ARROW-9235 we have a problem where we need to evaluate code (may be C++ that calls the R API in a way that may allocate R memory or literal R code) on the R main thread. As discussed in the pull request ( https://github.com/apache/arrow/pull/12323#issuecomment-1054726309 ), there are other times that this has come up and will come up in the future (e.g., evaluating user-defined R functions from the query engine, implementing extension types from R).

      After discussing with westonpace, it seems like it is worth investing in a SafeCallFromR() C++ function that lives in the R bindings. The initial approach (that may need to be altered as we go) will be to

      • have a global object that is initialized at the beginning of a C++ call from R to specific functions (and released on exit) that maintains some list of tasks that need to run on the R main thread and an event loop to periodically evaluate them while background tasks are running.
      • define a SafeCallFromR() C++ function that adds a task to the global object and waits for the result to come back.

      (with apologies to Weston if I mischaracterized our conversation!)

      Attachments

        Issue Links

          Activity

            People

              paleolimbot Dewey Dunnington
              paleolimbot Dewey Dunnington
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3h 20m
                  3h 20m