Solved

Killing a Thread within a process.

Posted on 1998-04-14
7
4,052 Views
Last Modified: 2013-12-26
Is there a way to kill a ind. thread within a process
0
Comment
Question by:elcoco
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:elcoco
ID: 1292145
Edited text of question
0
 
LVL 5

Accepted Solution

by:
nebeker earned 150 total points
ID: 1292146
Depends if you own the thread or not....

DosKillThread() will toast any thread that your process created.  However, it is not exactly recommended because it does not allow the thread to do any cleanup work before it exits.

I also remember some hazards using DosKillThread to toast threads that were created with beginthread instead of DosCreateThread...

The best way is to set some kind of notification flag for the thread, and let it do its cleanup and then exit.

If you are trying to kill an individual thread from another process, then I don't know how to do it.  You might be out of luck....

You also might want to mention *why* you want to kill a thread - there might be a better way of doing it than just destroying the thread...
0
 
LVL 2

Expert Comment

by:sprinkmeier
ID: 1292147
More info please!
what's an 'ind. thread'?
Are you in the same process?
Do you have the process ID?
Does the thread need to do any cleanup?
Is the thread likley to terminate itsself? (ran into this one, OS/2 reuses thread IDs so if you ask thread N to die, and it does, and another  one starts with thread ID N, and then you kill thread ID N thinking it;s the original one still hanging around, you;re in trouble!)

The quick answer is DosKillThread()

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:elcoco
ID: 1292148
thanks, i have an oem package that is creating threads but not cleaning them up. therefore i eventually run out of avail. threads.  the manufact. is slow to resolve this is.  i'm trying to either create a work around or another app. that could close threads that have been inactive. i dont know if this is possible from your answer....would be grateful for any help you can provide
0
 
LVL 5

Expert Comment

by:nebeker
ID: 1292149
As far as I know, one process cannot kill individual threads from another process.

If you were to shut down the offending process, all of its dead threads would go along with it.  Is there any way you can "restart" the problematic program every once in a while?  (Kind of like the trick used to keep Windows NT servers running - reboot them every night at midnight <g>)

In order for your system to truly run out of available threads, this process must be creating hundreds of them....  How long does it take to run out, and how many threads are in the system when it finally dies?
0
 
LVL 2

Expert Comment

by:sprinkmeier
ID: 1292150
Another problem qould be determining which of th threads are idle.
Why not just bump up the threads to the max (4095)?
That should keep the app busy chewing them up for a while.

0
 

Author Comment

by:elcoco
ID: 1292151
Thanks, i have already bumped them up to 4095...the app does open quite a bit of
 threads. its opening an sql table and writing to an ascii file. it will open a thread for each
read AND write. it does this hourly for approx. 40 files with two data pieces a piece and the threads are exhausted after a few days....i can reboot this system,but the problem becomes automating the process. i guess i can figure something out. since i dont have the source code i cant fix and recompile.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 92
maxBlock challenge 30 142
notReplace  challenge 53 141
sum67 challenge 35 107
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question