About Store Forum Documentation Contact
Donations:
206$/mo



Post Reply 
Multithreaded custom edit call clarification
Author Message
Abril Offline
Member

Post: #1
Multithreaded custom edit call clarification
Hello, would like a clarification on this comment/functionality:

Edit::World.grid.mtFunc(Edit::Brush.affectedArea(), CustomEdit); // call 'CustomEdit' on all areas affected by the brush, please note that here 'mtFunc' is used which makes calls on multiple threads

static void CustomEdit(Cell<Edit::Area> &cell, Ptr) // function performing custom operation on area

Does it mean that for example, if the editor brush is spanning two areas, would it call CustomEdit on 2 different threads, one for each area (the functionality I would be expecting)?
05-13-2012 09:17 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Multithreaded custom edit call clarification
Yes, mtFunc utilizes all available hardware threads.
and CustomEdit will be called on multiple threads.
05-16-2012 11:53 AM
Find all posts by this user Quote this message in a reply
Abril Offline
Member

Post: #3
RE: Multithreaded custom edit call clarification
(05-16-2012 11:53 AM)Esenthel Wrote:  Yes, mtFunc utilizes all available hardware threads.
and CustomEdit will be called on multiple threads.

The issue is with calling Edit::World.objCreate inside CustomEdit on multiple threads. Seems like it is not thread safe, is crashing somewhere in Editor Undo.
For now I got it working by separating the Edit::World.objCreate operations in a non multithreaded call, but this is far from optimal.

1) Is there some other way of adding objects to an area within the multithreaded mtFunc call which will not result in a crash?

2) Or is there a way to manually disable the Editor Undo, which I won't need anyway, and which is causing the crash as far as I can see (but of course might not be limited to Undo, there could be other issues with making Edit::World.objCreate working on multiple threads)
05-24-2012 12:05 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Multithreaded custom edit call clarification
Hello,

EE::Edit::World methods are not thread safe.
If you want to call objCreate by the usage of mtFunc, you may want to try surrounding objCreate calls with a custom global Critical Section, I think that should be enough.

http://www.esenthel.com/wiki/index.php?t...ead_Safety
05-26-2012 10:16 AM
Find all posts by this user Quote this message in a reply
Abril Offline
Member

Post: #5
RE: Multithreaded custom edit call clarification
(05-26-2012 10:16 AM)Esenthel Wrote:  Hello,

EE::Edit::World methods are not thread safe.
If you want to call objCreate by the usage of mtFunc, you may want to try surrounding objCreate calls with a custom global Critical Section, I think that should be enough.

http://www.esenthel.com/wiki/index.php?t...ead_Safety


Hi,
a critical section is still not enough, btw you can easily repro the issue with the vanilla editor source code, if you create any object inside

void EditAreaData::edit()

surrounding the objCreate call with a custom global critical section, it will still crash somewhere in the Undo code.

Anyway this is not urgent for me right now because I got it working by deferring the calls to into a non-MT function, but just leeting you know that a critical section is not enough and that disabling the Undo could still be very useful for other reasons.
Cheers
05-28-2012 10:54 AM
Find all posts by this user Quote this message in a reply
Daniel Mewes Offline
Member

Post: #6
RE: Multithreaded custom edit call clarification
If critical sections won't do the trick, you could try it with a mutex or if you implemented multithreading with the boost library you could take a look at strands.
05-30-2012 07:00 AM
Find all posts by this user Quote this message in a reply
Post Reply