[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ExitThread memory leaks?

Posted on 2001-08-27
5
Medium Priority
?
1,215 Views
Last Modified: 2013-12-03
I was looking up CreateThread in my Win32 documentation when I noticed a little paragraph at the bottom:

"A thread that uses functions from the C run-time libraries should use the beginthread and endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called."

Is this true? The "For example, see Creating Threads" link on the page leads to an example program that uses wsprintf in the thread. Kind of hypocritical.

If it's true, then does it mean that I have to implement copies of the CRT functions that I use?
0
Comment
Question by:TookH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 400 total points
ID: 6430979
>>Is this true?

Yes

wsprintf() is a Windows API function, and not C run-time function, you mixed it up with sprintf() etc.

>>then does it mean that I have to implement copies of the CRT functions that I use?

Not at all, to create a thread use C run-time functions _beginthread() and _beginthread()
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 6430988
I meant to say _beginthread() and _beginthreadex(). The latter one is almost the same as CreateThread() with regard to the parameters.

The difference is that you can use any C function inside the thread. To terminate the "C" thread simply return or call _endthread() or _endthreadex().
0
 
LVL 1

Author Comment

by:TookH
ID: 6432563
I find this really disturbing! I've seen so many sample programs that use CreateThread and CRT functions. Does MFC's thread class use CreateThread or beginthread? How significant are the leaks?
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 6435434
>>Does MFC's thread class use CreateThread or beginthread?
Sure, beginthread. See "C:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\THRDCORE.CPP"

>>How significant are the leaks?
Well, it is not disturbing at all to call beginthread instead of CreateThread. beginthread initializes some thread-related memory; with CreateThread some of RTL functions might work incorrectly or not work at all.
0
 
LVL 1

Author Comment

by:TookH
ID: 6435574
I suppose I should just get used to using beginthread, then. It makes me angry, though. What is the point of putting a function in a library if it causes bugs in 90% of the programs it's used in?

Are there events, critical sections, ect. for use with beginthread?
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question