1. 程式人生 > >Some tips about the life cycle of Maya thread pool

Some tips about the life cycle of Maya thread pool

If you want to know how to use MThreadPool, besides the above link, you can reference our 2 samples, threadTestCmd and threadTestWithLocksCmd. But here, I just want to talk about the life cycle of the thread pool.

If you check with the above 2 samples, you will see MThreadPool actually be released twice by MThreadPool::release() as follow, why? And what is 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 that whenever the thread pool is created, it actually sets the count reference to 1, instead of 0, so when we call MThreadPool::init(), the cound reference will be increased to 2. So if you release it once, it just decrease the reference count to 1, which will not kill the thread pool, you have to always release it one more time to make it be destroyed. What the benifit for this behavior? Actually, from the online SDK, it says "Since creation and deletion of threads is expensive, it is 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 each call.", so everything is clear now, Maya will keep the thread pool alive during the life cycle to save the performance, and it always survives unless you manually decrease the reference count to 0.     

相關推薦

Some tips about the life cycle of Maya thread pool

If you want to know how to use MThreadPool, besides the above link, you can reference our 2 samples, threadTestCmd and threadTestWithLocksCmd. But here,

Some tips about the C++(自己看的,很亂)

...{    char str1[] ="abc";    char str2[]="abc";    constchar str3[]="abc";    constchar str4[]="abc";    char* str5 ="abc";     char* 

Some tips about using google’s TPU

About one month ago, I submit a request to Google Research Cloud for using TPU for free. Fortunately, I received the approvement yesterday. The appro

Some tips about using google’s TPU (Cont.)

Sometimes I get this error from TPUEstimator: ... File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/s

Unmanned: a video game about the unseen horror of drone warfare

According to mainstream video games, modern warfare is all about cyborg arms, laser shields and jarheads blowing up baddies under the guidance of recognisa

Some tips about layout

對於Android開發來說佈局說簡單很簡單,說難也挺難的,簡單總結一些常用的技巧或者方法吧(持續更行) tip 1: layout_weight的妙用 在有些場景下,比方說 場景一:我們在螢幕下方的一個linearlayout中擺了四個button,我們希望無論什麼情況下,

asp.net: what's the page life cycle order of a control/page compared to a user contorl inside it?

life should .com div sid ros ges tco sta https://stackoverflow.com/questions/7335142/asp-net-whats-the-page-life-cycle-order-of-a-control

About the diffrence of wait timed_wait and block in java

@override stack util except str void rgs dex interrupt import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Reentra

A cycle was detected in the build path of project

java在ecilpse 的 控制臺 旁邊 的problems 旁邊 出現 A cycle was detected in the build path of project ...解決Eclipse中Java工程間循環引用而報錯的問題 如果我們的項目包含多個工程(project),而它們之間又是循環引用的關

A cycle was detected in the build path of project項目相互依賴

pre lips war 報錯 ces bsp clip cli ble 解決Eclipse中Java工程間循環引用而報錯的問題 如果我們的項目包含多個工程(project),而它們之間又是循環引用的關系,那麽Eclipse在編譯時會拋出如下一個錯誤信息: “A cycle

a report about the history of pragrem

第一個寫軟體的人是Ada(Augusta Ada Lovelace),在1860年代她嘗試為 Babbage(Charles Babbage)的機械式計算機寫軟體。儘管他們的努力失敗了,但他們的名字永遠載入了計算機發展的史冊。她的父親就是那個狂熱的,不趨炎附勢的激進詩人和冒險家拜倫。她本身也是一個光彩照人的人

@ · Also worried about the quality of air, air purifier detailed?

Air quality is good and bad, so that the public more worried, and if the home has a pet, or just finished decoration, air purifier

2018年9-12月份雅思口語題庫素材(原創)describe the first cellphone of yours that brought changes to your life

When I was a child in the primary school, I always used my parents’ phone. After studying in the high school, I hoped to own a phone bel

Ask HN: Resources about the fundamentals of programming languages?

Hi HN, what is your favorite book/course to learn about the fundamentals of programming languages?My goal is to learn more about things like different ways

Some Thoughts about Productivity and the 40 Hour Work Week

Some Thoughts about Productivity and the 40 Hour Work WeekOne thing I really care about is productivity, and one thing I hate is busyness. Being busy doesn

Surviving the Existential Crisis of life as a product manager

Surviving the Existential Crisis of life as a product managerIn the world of product management, there’s one question that remains difficult and frustratin

42 Cutting Edge Facts About the Past, Present and Future of Artificial Intelligence

People have been dreaming about Artificial Intelligence for hundreds, if not thousands of years. Well, it's starting to feel like the future is actually he

Provost's letter to the faculty about the MIT Stephen A. Schwarzman College of Computing

The following email was sent today to the MIT faculty from Provost Martin Schmidt. Dear colleagues, As I trust you have seen, this morning Rafael wrote to

dumped the major features of my life with ADHD and how I manage it | Hacker News

I've had to take a bit of time off work due to being ill, which gave me a great opportunity to sleep a lot and write the longest thing I've

Ask HN: What are some of the dark sides of being in the tech industry?

Computers always had an aura of infallibility to me as a kid. But learning to program taught me that they're only as infallible as their creators, program