Some tips about the life cycle of Maya thread pool

Source: Internet
Author: User

As you know, Maya provides class Mthreadpool to help develop to create or reuse a thread pool, if you want to kno W More on this, you can reference the online SDK at http://help.autodesk.com/view/MAYAUL/2015/ENU/?guid=__files_GUID_2 Bef58d3_6162_4235_a6ce_3d8b0742a0ae_htm and Http://help.autodesk.com/view/MAYAUL/2015/ENU/?guid=__cpp_ref_class_ M_thread_pool_html.

If you want to know what to use mthreadpool, besides the above link, you can reference our 2 samples, Threadte Stcmd and threadtestwithlockscmd. But here, I just want-talk about the life cycle of the thread pool.

If you check with the above 2 samples, you'll see Mthreadpool actually is released twice by Mthreadpool::release () as Fo Llow, why? And what are the purpose of doing each one? I am also interested in this, so I just spend some time-to-dig into the source code.

Code Snippet
    1. Pool is reference counted. Release reference to current thread instance
    2. Mthreadpool::release ();
    3. Release reference to Whole pool which deletes all threads
    4. Mthreadpool::release ();

When I dig into the code, I find this whenever the thread pool is created, it actually sets the count reference to 1, inst EAD of 0, so if we call Mthreadpool::init (), the Cound reference would be increased to 2. If you release it once, it just decrease the reference count to 1, which would not kill the thread pool, and you had to ALW Ays release it one more time-to-make it be destroyed. What is the benifit for this behavior? Actually, from the online SDK, it says "Since creation and deletion of threads are expensive, it's a good idea to make use Of the thread pool where possible, and try to keep it around between invocations of the plug-in rather than recreate it E Ach call., so everything are clear now, Maya would keep the thread pool alive during the life cycle to save the performance , and it always survives unless your manually decrease the reference count to 0.

Some tips about the life cycle of Maya thread pool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.