Page 1 of 1

rayTest from multiple threads? Is it safe?

Posted: Fri Oct 03, 2014 3:00 pm
by varoudis
Hi all,

I want to do raycasts from many threads simultaneously.
While doing so, NO 'world update' will happen and no changes on any object.
(maybe some debugdraw but I can eliminate that too if it helps).

Is this (multi-threaded raycasting on a single world) thread-safe?
Will I get the correct ray hits?

Thanks
T

Re: rayTest from multiple threads? Is it safe?

Posted: Sat Oct 04, 2014 10:26 am
by Basroil
varoudis wrote:Hi all,

I want to do raycasts from many threads simultaneously.
While doing so, NO 'world update' will happen and no changes on any object.
(maybe some debugdraw but I can eliminate that too if it helps).

Is this (multi-threaded raycasting on a single world) thread-safe?
Will I get the correct ray hits?

Thanks
T
If you make the calls before stepping the world, nothing should change (assuming you don't add/remove/move anything yourself), and I've had relatively good experiences with read-only functions. Is it truly thread safe? Probably not unless Erwin posts here or comments in the code, though you can test to see if it's good enough if you use VS2013 and watch your threads in parallel.

Re: rayTest from multiple threads? Is it safe?

Posted: Sat Oct 04, 2014 10:41 pm
by RyanFavale
In my experience, no, unless something has changed recently.
If you find it to be thread safe, let us know!
I would like to do some raycasts for ambient occlusion testing in the background while generating terrain.

Re: rayTest from multiple threads? Is it safe?

Posted: Sun Oct 05, 2014 4:15 pm
by varoudis
thats not good :(

Maybe Erwin can confirm?
At least without doing any world step or world modification, it should be thread safe.

Thanks
T

Re: rayTest from multiple threads? Is it safe?

Posted: Mon Oct 06, 2014 5:44 am
by c6burns
You cannot be raycasting from one thread while you are stepping the world in another. There is a class called SpuBatchRaycaster which seems to allow a batch of raycasts to be performed across multiple threads, though I have never tested it. It is in a few of the example apps ... search for:
#ifdef BATCH_RAYCASTER

Re: rayTest from multiple threads? Is it safe?

Posted: Mon Oct 06, 2014 7:27 am
by varoudis
thanks c6, ill look for it.

of course Im not doing ANY step/update from ANY thread during multi-threaded casting.

Re: rayTest from multiple threads? Is it safe?

Posted: Fri Oct 10, 2014 12:57 am
by Erwin Coumans
The ray cast should be treadsafe/re-entrant, as long as you don't step/change the world during the ray cast.

If not, please report back,
Erwin