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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:21:26+00:00 2026-05-26T22:21:26+00:00

Working with C and Win32, I have a problem where my program freezes instead

  • 0

Working with C and Win32, I have a problem where my program freezes instead of closing when a quit message is posted(Alt-F4 for example), and I have to end the process with task manager.

I have this in my main loop:(problem solved)

MSG msg;
while(1)
{
    while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
    {
        if(msg.message == WM_QUIT)
        {
            terminate = 1;
            while(terminate != 3) //each thread increments "terminate" by 1 before returning
            {
                Sleep(1);
            }
            return 0;
        }
        DispatchMessage(&msg);
    }
    Sleep(1);
}

It will print “OK!” in the console and then freeze.

I think this could be because I have multiple threads and they are not terminated properly (but I read that if I return from my main() function the other threads should be killed automatically). If it helps one of those threads is an OpenGL rendering 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-05-26T22:21:27+00:00Added an answer on May 26, 2026 at 10:21 pm

    The main function is only just a thread, you are terminating just that one. However, for a process to end, all threads need to be properly terminated or it will run forever. You’ll need to keep a reference the threads and terminate them once you receive the WM_QUIT message.

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

Sidebar

Related Questions

I am working on a c++ win32 program that involves a keyboard hook. The
Simple problem. I'm working on a Delphi 2007/WIN32 application which now uses MS Access
I have a problem with the timers in my win32 C++ DirectX game (a
I'm working on a multi-threaded win32 MFC application. We are rendering a map and
I am working on a legacy project in VC++/Win32/MFC . Recently it became a
I'm working on an instant messenger client in C++ (Win32) and I'm experimenting with
I am working on an application/GUI created with Win32/ATL . So there is UI
I'm working on C++ project that is supposed to run on both Win32 and
Is there a Win32 equivalent to the linux header file? I'm working on a
Working on a project at the moment and we have to implement soft deletion

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.