rayTest from multiple threads? Is it safe?

Post Reply
varoudis
Posts: 5
Joined: Sat Jan 22, 2011 11:24 am

rayTest from multiple threads? Is it safe?

Post 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
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: rayTest from multiple threads? Is it safe?

Post 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.
RyanFavale
Posts: 9
Joined: Mon Jan 17, 2011 11:10 pm

Re: rayTest from multiple threads? Is it safe?

Post 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.
varoudis
Posts: 5
Joined: Sat Jan 22, 2011 11:24 am

Re: rayTest from multiple threads? Is it safe?

Post 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
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: rayTest from multiple threads? Is it safe?

Post 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
varoudis
Posts: 5
Joined: Sat Jan 22, 2011 11:24 am

Re: rayTest from multiple threads? Is it safe?

Post by varoudis »

thanks c6, ill look for it.

of course Im not doing ANY step/update from ANY thread during multi-threaded casting.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: rayTest from multiple threads? Is it safe?

Post 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
Post Reply