Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


More Threads Problems

This topic is 5601 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

Does CreateThread not give a unique handle to every thread that is created? In other words, wouldn''t the following code create 4 unique threads each with a unique HANDLE and push that handle onto the vector vRecvThreadPool? The reason I ask is that the cout statement following the call to push the handle onto the vector always outputs the exact same thing: 0x00000000. I''m trying to debug this program. It runs but this output just seems peculiar.
for (iThreadCount=0; iThreadCount < 4;
    hThreadHandle = CreateThread(NULL, NULL, RecvDispatch,
                        reinterpret_cast< LPVOID >(pRecv),
                        NULL, &dwThreadID);
    if (hThreadHandle = NULL)
	perror("Recieve Thread Creation Problem");
    cout << hThreadHandle << endl;			
Another problem that is generating an actual error is my actual thread function (worker function). In that function, if I make any call to an STL object the program crashes. Are STL objects not thread safe? For now I am only running the program with a single thread and only that thread does anything with the queue in question so it shouldn''t be an issue of multiple threads mangling the memory. Example: if(vRecvThreadPool.size() == 1) { cout << "GOOD UNTIL HERE" << endl; } will genenerate a runtime error (program dies) but if(1<2) { cout << "GOOD UNTIL HERE" << endl; } will work just fine. All of my errors are isolated around STL objects I am using. Whether it''s a call to .size(), .push_back(), or whatever. Should I be using a critical section or a mutex around these no matter if I only have 1 thread or more? Thanks for any help, Webby

Share this post

Link to post
Share on other sites
Original post by cbenoi1
> if (hThreadHandle = NULL)



If you missed this:

It should be ==, since you''re comparing.

Share this post

Link to post
Share on other sites
Ahhhh, the joys of the little mistakes that bite you in the ass

Still got the issues with the STL objects though.

Thanks guys. Can''t believe I missed that one...


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!