terminate threads in managed c++

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I have thread that recives event notifications from a server.

the thread is created as a managed thread. But when using Thread Abort the
thread doesn't terminate.

the thread is in an waitable state using WSAWaitForMultipleEvents.

How can I kill this thread, i don't mind brute force.

/Steffo
 
Hi I have thread that recives event notifications from a server.

the thread is created as a managed thread. But when using Thread Abort the
thread doesn't terminate.

the thread is in an waitable state using WSAWaitForMultipleEvents.

How can I kill this thread, i don't mind brute force.

/Steffo

Hi Steffo,

You can't! Use a timeout with WaitForMultipleEvents and then use this
information

http://groups.google.com/groups?hl=...8m%24gbl%241%40news1.tilbu1.nb.home.nl&rnum=1

to check if the CLR wants your thread to abort. ExitThread can then be
called.

Ferdinand.
 
How can I kill this thread, i don't mind brute force.

This is a design flaw. Please redesign your threads to shutdown by logic,
not by force.
 
You are mixing managed code (threding) with unmaganed code
(WSAWaitForMultipleEvents) . You are killing a managed code that has
unmanaged logic, this could be the reason it does not work. Maybe the
unmanaged code spinns off a new thread in some libraries... Anyway killing a
thread is a design flaw.

Send a "thread shutdown" event to the thread and your event-handler. Use
this event to break out of the event handler loop and let the thread die on
its own. How you design this "thread shutdown event" is up to you. The
framework does not give you this.

Use signals/events in the main thread so the main thread does not shutdown
before all child threads have died on their own.


Or you could make a timeout on the waiting call and use a shared variable
(critical section) with the mail thread, to control the event handler loop
to let the thread die on its own.


The solution is to design the thread to die on its own, and don't shutdown
the main thread before all child threads have died. Use event/signal to
achieve this. Eg store all threads in a vector/list structure so you easily
can traverse this structure before you shutdown the main thread/app.

Did this make any sense?
 
Back
Top