Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:08:59+00:00 2026-06-18T11:08:59+00:00

It would be extremely useful to me to be able to create a function

  • 0

It would be extremely useful to me to be able to create a function in R that could block until a resource is defined or is given the appropriate value. I know that R is single-threaded, but I had hoped that mc would be able to help. However,

library(parallel)
f = function() {
  while(!exists('a')) Sys.sleep(1);
  print('success!')
}
d = mcparallel(f())
a = 1
mccollect(d)

hangs indefinitely. Is there any effective workaround, or will I have to look into radically different patterns/a different language to achieve something of the sort?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:09:01+00:00Added an answer on June 18, 2026 at 11:09 am

    I didn’t even know it was possible to fork processes like that. After playing around for a bit, I found the sendChildStdin function, which you should check out. It is at least one way to signal the child processes. Here is an example:

    f<- function () {
      message<-scan(n = 1, quiet = TRUE, what='character')
      return(message)
    }
    p  <- mcparallel(f())
    a <- 1
    # The message shouldn't contain spaces and should end with a newline.
    parallel:::sendChildStdin(p, "created\n") 
    mccollect(p)[[1]]
    [1] "created"
    

    Don’t get me wrong; R is probably not the language you want if you are going to get into the stuff heavily, but it might work for light applications.


    I had tested the code before in RStudio, and although it appeared to work, it was failing in a way that was indistinguishable from success. Anyway, it essentially doesn’t wait for the scan process. For example, this should never complete, but it does (in RStudio only)

    f<- function () {
      message<-scan(n = 1, quiet = TRUE, what='character')
      return(message)
    }
    p  <- mcparallel(f())
    # parallel:::sendChildStdin(p, "created\n")
    mccollect(p)[[1]]
    # character(0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I find functools.partial to be extremely useful, but I would like to be able
It seems that it would be extremely handy to be able to filter a
I would first like to admit that I am an extremely novice developer, so
It would be extremely useful for web development.
I work with a lot of floating-point images, and would find it extremely useful
Could you help me figure out a regular expression that would extract from url:
Would be possible to extend this kind of layout so that I can have
Would like a for loop in jquery so that: For every hover_link: show hidden
I'm curious if anyone is using any web app that is extremely simple (very
This article states that Despite the fact that the Mersenne Twister is an extremely

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.