Archived

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

WebsiteWill

More Threads Problems

Recommended Posts

WebsiteWill    134
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;
     iThreadCount++)
{
    hThreadHandle = CreateThread(NULL, NULL, RecvDispatch,
                        reinterpret_cast< LPVOID >(pRecv),
                        NULL, &dwThreadID);
    if (hThreadHandle = NULL)
    {
	perror("Recieve Thread Creation Problem");
	exit(1);
    }
    
    vRecvThreadPool.push_back(hThreadHandle);
    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
Nerusai    103
quote:
Original post by cbenoi1
> if (hThreadHandle = NULL)

Hmmmmm....

-cb


If you missed this:

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

Share this post


Link to post
Share on other sites
WebsiteWill    134
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...

Webby

Share this post


Link to post
Share on other sites