mercredi 1 juillet 2015

sleep_for() doesnt work with detached thread

I'm working on application which collects data from GPS receiver with Raspberry Pi and sends signals to camera to take photos. GPS receiver connects to Rapberry via UART so i created monitor class as singleton. Monitor works in detached thread and collects navigation data. Main() collects photos with target frequency. Problem is that sleep_for() doesnt work in main(). Code sample:

void gps_run(uart_monitor* &m)
{
    m->Run();
}

int main()
{
uart_monitor* m = uart_monitor::Instance();
m->Set(Coord, CoordBufMutex);
thread gps_monitor(gps_run,ref(m));
gps_monitor.detach();

    //Test camera shutter
    for (int rep=0; rep<10; rep++)
    {
         GPIO_SET = 1<<GPIO;
         printf("On...\n");
         std::this_thread::sleep_for(std::chrono::milliseconds(300));
         GPIO_CLR = 1<<GPIO;
         printf("Off...\n");
         std::this_thread::sleep_for(std::chrono::milliseconds(2000));
    }

return 0;
}

Programm makes only one "blink" but prints all "On.../Off..." sequence. Whithout gps_monitor thread it works fine.

Aucun commentaire:

Enregistrer un commentaire