Jump to content

HDK Vex initialize function and multithreading


Recommended Posts

///////////////////

I'm writing a custom c++ vex function.  I have a somewhat expensive initial setup that only needs to be done once per instance(not per thread).I have the following scenarios working already:

 

1) multi-threaded off.  Each time the vex function is instanced, my initial setup is called once.  This is fine, but single-threaded.

2) multi-threaded on.  Each time the vex function is instanced, each thread calls the initial setup once.  This is working, but too heavy, not optimal.

3) multi-threaded on.  Initial setup is done in a singleton class which is forced to be called only once.  This is similar to the gamma table example in the help.  Initial setup is called only once, but on subsequent instantiation, each instance shares the same initial setup.  This is not correct, as each instance will require a different setup.

 

What I'd like is:

multi-threaded on. Initial setup is done once per instance, and shared among all the threads invoking that instance. Once the vex function is used again, initial setup is done only once again, not 1*numthreads.

///////////////////

 

Also, is there any way to pass in input args data from parameters to the initialize function?  Currently they only seem to be passed to the evaluate function.

 

 

Link to comment
Share on other sites

A question:  In a vex function multi-threading scenario, how can I determine which instance certain threads belong to?

 

Background information:

I've come up with a way to cache information for the threads throughout the Init, evaluate, cleanup vex function lifecycle.  However, I'm running into a problem. 

 

When I advance frame by frame slowly, one by one, my function is stable with multi-threading on. When I play it back at realtime, it crashes after a couple of frames.  However, if I cause each thread to print out information to the console during cleanup and init, it plays back without crashing. I believe I know the reason, but I can't think of a solution within the current architecture.

 

Each thread has no awareness of whether the other threads have finished their cleanup.  I also don't see any way to determine which instance different threads belong to.  When some threads move on to the next init function, and other threads are still in the previous cleanup function, this causes a crash (since I've set it up so that all threads are sharing the same per-frame global data). I may have multiple instances of my custom vex function within the same process, and I don't see a way to deal with this per instance.  Is there anything like getMyInstance() for the entire instance?

 

The documentation states "The initialization/cleanup functions are called for each instance of your user function."  However, I found instead that the initialization and cleanup functions are run per thread.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...