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 7677453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:25:34+00:00 2026-05-31T17:25:34+00:00

I just learn the bare bone of making a thread inside a program using

  • 0

I just learn the bare bone of making a thread inside a program using process.h in C programming. And now, my problem is how to stop a specific thread.

Here is my code:

#include <stdio.h>
#include <windows.h>
#include <process.h>    

void  mimicCounter( void * );   

int main()
{
    int i;


    printf( "Now in the main() function.\n" );

    _beginthread( mimicCounter, 0, (void*)12 );

    for(i = 2; i <= 10; i++){
          Sleep(500);
          printf("%d\n",i);
    }

    system("PAUSE");
    printf("\n");
}

void  mimicCounter( void *arg )
{
    int i;
    printf( "The mimicCounter() function was passed %d\n", (INT_PTR)arg ) ;
    for(i = 1; i <= 10; i++){
          Sleep(500);
          printf("%d\n",i);
    }
}

I just want to stop the thread that I have created (the mimicCounter function) when it reaches i = 5, (yeah I know I set it to 10 but this is for ending a thread demo).

Thank you so much 🙂

  • 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-05-31T17:25:35+00:00Added an answer on May 31, 2026 at 5:25 pm

    The _endthread and _endthreadex functions terminate a thread created by _beginthread or _beginthreadex, respectively. You can call _endthread or _endthreadex explicitly to terminate a thread; however, _endthread or _endthreadex is called automatically when the thread returns from the routine passed as a parameter to _beginthread or _beginthreadex. Terminating a thread with a call to endthread or _endthreadex helps to ensure proper recovery of resources allocated for the thread.

    From http://msdn.microsoft.com/en-us/library/aa246804(v=vs.60).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started to learn about mod rewrite process. Now, I got some problems
I'm learning C# and now I need to build a home project(just to learn
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I
I am new to jQuery.just learn and use it for 3 weeks until now.
I'm making an extremely simple CMS in ASP.NET MVC 3 (just to learn it)
Just starting to learn the CakePHP framework. I'm using the Auth component, and all
Just beginning to learn about structs, I thought I understood how they work, using
Just for learn: Say we have: interface Musician { /* content skipped */ }
I am doing some tests, just to learn (normally i do this in ajax
I just started to learn how to use action listeners. To my understanding it

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.