Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

windows - std::thread increase DLL reference count? How?

I created a thread within a loaded dll by using std::thread. Then I unloaded the dll at main thread and try to reproduce the error that living thread running with unloaded codes. However, I notice the DLL cannot be unloaded after calling FreeLibrary. I was using Visual Studio Modules View for knowing if the DLL is unloaded. The DLL is unloaded after the thread is finished. I notice there is a similar ticket mentions that std::thread increase the reference count. I think it should make sense and I tried to read the implementation of the constructor of std::thread(MSVC version). I can see it uses _beginthreadex internally, but I cannot figure out which statement increase the DLL reference count. So my question is where is it?

If my theory above is wrong at the root, how the running thread prevent DLL from being unloaded?

By the way, I also tried creating thread by using CreateThread, DLL can be unloaded and I can see the expected result (crash as my expected).

By the way again, how is it on Unix platforms?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...