Skip to content
Prev 14583 / 21312 Next

[Bioc-devel] [Untrusted Server] Rprintf in a multi-threaded environment

Thanks, Shian!

Yes, I think the only way to make it work is to send the messages to the main thread.

Cheers,
Yang

-----Original Message-----
From: Shian Su <su.s at wehi.edu.au>
Sent: Tuesday, 29 January 2019 3:22 PM
To: Yang Liao <liao at wehi.edu.au>
Cc: bioc-devel at r-project.org
Subject: Re: [Untrusted Server][Bioc-devel] Rprintf in a multi-threaded environment

Hi Yang,

That was my SO thread you found, and as you can see, the issue was never clearly explained to me besides the warning in the docs. I don?t believe anything?s changed to allow the R API to be called from different threads, so extra effort is still required.

What I ended up doing in my code was the hack shown in the second code-snippet, handling output only in the main thread. For your situation depending on what kind of work you are doing, you may consider a thread safe queue to push your progress messages to and a condition variable to ask the main thread to flush the queue to output. I imagine this would be simpler if your do all your work in spawned threads and leave the main thread free to only print output periodically.

Kind regards,
Shian Su
_______________________________________________

The information in this email is confidential and intended solely for the addressee.
You must not disclose, forward, print or use it without the permission of the sender.

The Walter and Eliza Hall Institute acknowledges the Wurundjeri people of the Kulin
Nation as the traditional owners of the land where our campuses are located and
the continuing connection to country and community.
_______________________________________________