Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Killing thread in blocking call...

Status
Not open for further replies.

mattKnight

Programmer
May 10, 2002
6,235
GB
Hi,

relative newbie to C++, even newer to multi-threading; so please be gentle!

I am currently investigating (playing with) multi-threading, synchronisation etc.

my query is this...
Code:
DWORD WINAPI ListenerSocket::WorkerThreadProc(LPVOID lpParameter)
{
      myClass *pThis; 
	pThis = reinterpret_cast<myClass *>(lpParameter);

//      pThis now allows access to class methods & member variables from this static method


while(!pThis->mbThreadStop)
 {
  long lRet;
 
   lRet = myBlockingCall(pThis->GetMyInfo());
   // TO DO
   // Other useful code relying on return from blocking call
  }
}

I am sure you get the idea!

Suppose I want to kill the thread, whilst the thread is blocked waiting for myBlockingCall?

If mbThreadStop is set true, the thread will exit after myBlockingCall, which may not be the desired response! 

I could use TerminateThread(), but isn't that a bit &quot;brute force&quot; or am I looking for a neat solution to a problem that can only be solved by the bruteforce approach.

I am sorry, but this is a little abstract, the above code is an example only.

Thanks!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
TerminateThread/CloseHandle are a bit brute, but sometimes you have nothing else to do.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top