Jump to content
  • Advertisement
Sign in to follow this  
mrmrcoleman

Could somebody just check this for me...

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have this piece of code...
m_hThread = (HANDLE)_beginthreadex(0,0,CSerialCommHelper::ThreadFn,(void*)this,0,0);

DWORD dwWait = WaitForSingleObject ( m_hThreadStarted , INFINITE );
		
ASSERT(dwWait == WAIT_OBJECT_0 );

CloseHandle(m_hThreadStarted);

I just need to confirm that I know what it is doing... Am I correct in saying that this code will create a thread, and then wait for the thread to be started before it continues? Thanks, Mark.

Share this post


Link to post
Share on other sites
Advertisement
No, it will create a thread and wait for it to finnish before it continues.
edit:
if you want to wait for a thread to start create a shared event object wait for that and have the waitee trigger the event when it starts.

Share this post


Link to post
Share on other sites
Oh sorry, I missed out a vital piece of code. What about this...?


// Create the thread handles and start the thread
GlobalThreadTermEvent = CreateEvent(0,0,0,0);
GlobalThreadStartEvent = CreateEvent(0,0,0,0);

GlobalThreadHandle = (HANDLE)_beginthreadex(0,0,CommThread,0,0,0 );

DWORD dwWait = WaitForSingleObject(GlobalThreadStartEvent, INFINITE);

ASSERT(dwWait == WAIT_OBJECT_0);

CloseHandle(GlobalThreadStartEvent);


Share this post


Link to post
Share on other sites
That looks right, I missed that you had diffrent handles in your first version (probably due to the missing blocks).

And if you plan on using the "Term" event to wait for the thread to terminate you could just wait on the thread handle instead.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!