0

I'm working on my radio transmitter and have just ported it to Linux. Here is the problem:

void input_thread()
{
    char buffer[128];
    cout << "Waiting for input\n";
    for (;;)
    {
        cout << "say> ";
        if (cin.getline(buffer, 127).fail())
            // Ctrl+C
            break;
        else if (strlen(buffer) == 0)
            continue;
        signal_source.feed(buffer);
    }
}

I use a std::thread and hope it break the loop when gets a Ctrl+C. This piece of code works well on Windows but not on Linux. I'm wondering if there is a way to safely break the loop so that I can join the thread without causing deadlock? Thanks.

Mantosh Kumar
  • 5,659
  • 3
  • 24
  • 48
babel92
  • 767
  • 1
  • 11
  • 21

0 Answers0