Skip to main content
GameDev.net gamedev.net
🔒 Locked

More Threads Problems

Started by WebsiteWill Aug 10, 2003 at 2:59 PM 2 replies 400+ views
Original Post
WebsiteWill
WebsiteWill
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
cbenoi1
cbenoi1
> if (hThreadHandle = NULL)

Hmmmmm....

-cb
Nerusai
Nerusai
quote:
Original post by cbenoi1
> if (hThreadHandle = NULL)

Hmmmmm....

-cb


If you missed this:

It should be ==, since you''re comparing.
---Yesterday is history, tomorrow is a mystery, today is a gift and that's why it's called the present.
WebsiteWill
WebsiteWill
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.