Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8000447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:47:51+00:00 2026-06-04T15:47:51+00:00

What happens if we forcefully kill a running thread I have a thread namely

  • 0

What happens if we forcefully kill a running thread

I have a thread namely RecordThread() which calls some complex and time consuming functions. In these functions I am using try-catch blocks, allocating and deallocation memory and using critical section variables etc.

like

  void RecordThread()
  {
    AddRecord();
    FindRecord();
    DeleteRecord();
    // ...
    ExitThread(0);
   } 

After creating this thread, I am immediately killing it before the thread completes its execution. In this case what happens if the thread is forcefully killed? Do the internal functions (AddRecord, DeleteRecord) complete their execution after we killed the thread?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:47:54+00:00Added an answer on June 4, 2026 at 3:47 pm

    After creating this thread, I am immediately killing it before the thread completes its execution.

    I assume you mean you are using TerminateThread() in the following fashion:

    HANDLE thread = CreateThread(...);
    
    // ...
    // short pause or other action?
    // ...
    
    TerminateThread(thread, 0); // Dangerous source of errors!
    CloseHandle(thread);
    

    If that is the case, then no, the thread executing RecordThread() will be stopped exactly where it is at the time that the other thread calls TerminateThread(). As per the notes in the TerminateThread() documentation, this exact point is somewhat random and depends on complex timing issues which are out of your control. This implies that you can’t handle proper cleanup inside a thread and thus, you should rarely, if ever, kill a thread.

    The proper way to request the thread to finish is by using WaitForSingleObject() like so:

    HANDLE thread = CreateThread(...);
    
    // ...
    // some other action?
    // ...
    
    // you can pass a short timeout instead and kill the thread if it hasn't
    // completed when the timeout expires.
    WaitForSingleObject(thread, INFINITE);
    CloseHandle(thread);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What happens when I load some dll at run-time (let's call it Lib1.dll) but
It happens lot of the time that when you report a bug to a
It happens to me all the time. I accidentally version a file, I do
It happens all the time, I would need to scan my code for places
What happens internally when a functions that uses varargs is called? Are the arguments
Something happens in my system on a worker thread. Let's say that the state
What happens is we have a contact sync application. Soon after pressing a button
What happens when I update an app that has some files stored in the
This happens repeatedly and is very annoying. I upload some PHP code to a
What happens is that I have a list of tags that needs to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.