-1

NB: the original poster has requested that the question be closed; see comments.

After an C console program exits when triggering a "Press any key to continue" which is basically a CIN.ignore(), other CMD windows stop to respond to console input.

This happens when the program is executed from explorer window instead of from CMD. When the program starts in CMD it exits fine and other console windows are spared.

Tried cin.clear and getline with no luck.

Any ideas?

   pthread_t sthread;
   void *ret;
   start=true;      
   if (pthread_create(&sthread, NULL, &sbsb, (void*)listeningSocket)){
     cout << "[ERROR] unable to create thread for Server"<< endl;
     if(closesocket(listeningSocket))
   printf("[ERROR] CLOSE SOCKET FAILED WITH ERROR:%d\n",WSAGetLastError());
     WSACleanup();
   return -1;
  }    
    cout<<"[SOCKET] Started listening on "<<port<<endl;
    cin.ignore();
    start=false;
    cout<<"[END] Exiting"<<endl;
    if(closesocket(listeningSocket))
    printf("[ERROR] CLOSE SOCKET FAILED WITH ERROR:%d\n",WSAGetLastError());
    pthread_join(sthread,&ret);

    while (running_threads > 0)usleep(1);
WSACleanup();
    cout<<"[END] Bye SB"<<endl;
    return 0;  
Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
Bryan Huang
  • 5,247
  • 2
  • 15
  • 20

1 Answers1

0

Just resolved this by turning off the QuickEdit mode. See below for details:

Windows Console Application Getting Stuck (Needs Key Press)

My code was irrelevant to the issue just to clear things up.

Bryan Huang
  • 5,247
  • 2
  • 15
  • 20