Link to home
Start Free TrialLog in
Avatar of gilbert_chang
gilbert_chang

asked on

reentry of functions through different threads

I am reentring a function which creates a thread (inside the thread I am initializing & dealing with socket connection). As I said, this function is called a few times and is supposed to create a new thread each time.
When debbuging, I see that although I pass the lines in which the creating function is called, only the first thread is called (due to the first call to the function),
but no other threads are created.
Are there any restrictions on reentring functions?
Any restrictions on creating multiple threads that start with the same function?
Please give an example.
Thanks,
     Gilbert Chang
Avatar of nietod
nietod

How do you know no other threads are created?  How are you creating the threads?  Are you checking for error codes?  Do your realize that although a new thread may be created, it may not run right away.
Avatar of gilbert_chang

ASKER

I can view what threads are running while debugging using the icon that shows the debuggee's thread attributes in the VC++5.
I am creating threads using 'CreateThread'.
When looking for error codes, it seems like the threads are being created, but they dissapear quickly without doing their job...(running the function they should be started with)
If A thread does not run right away, how long can it take it? I am waiting for quite long periods of time (minutes!!).
Thanks.

They may take on the order of a hundred milliseconds or so.  For some code designs (bad ones) that can be a problem.  Can you post the code you use to start the thread and the code of the started thread?
In the InitInstance of my CApp (was created by the MFC wizard):
mAppPtr = new App;
mAppPtr->StartIt();
mAppPtr->StartIt();
mAppPtr->StartIt();

then:

void App::StartIt()
{
HANDLE threadHandle;
DWORD threadID;

threadHandle = CreateThread (NULL ,0 ,Routine , this , 0 , &threadID);
}

Status _stdcall App::Routine( void * pvoid)
{
App * pseudo_this = (App *) pvoid;
pseudo_this->InitConnection();
DWORD myExitCode;
ExitThread(myExitCode );
return TRUE;
}

App::InitConnection()

{
//
// Here I create a socket + neccesary definitions, bind and try to connect
//
}

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So is this working for you?  Need more help?
Thanks a lot!!