C++ Micro Second Timer with parallel thread in Linux/Ubuntu

Viewed 286

I created a timer and called for every 0.1 Millisecond. It's working good. But problem faced a Thread calling from timer. The timer calling infinite time.

I like to process 2 parallel thread or process inside the timer(with 0.1 millisec). Is this possible? I'm using ubuntu 12.04 LTS. Sample code as follows

int main(void)
{
    if (start_timer(0.1, &timer_handler)) //0.1 millisec timer caleed
    {
        printf("\n timer error\n");
        return(1);
    }
    while (1)
    {
        if (var > 10)       break;
    }
    stop_timer();
    return 0;
}

void timer_handler(void)
{
    int ret = 0;
    pthread_create(&thread, NULL, Test_thread, NULL);
    pthread_join(thread, (void **)&ret);
    printf("test_thread : %d\n", ret);
}

void *Test_thread(void *arg)
{
    pthread_exit((void*)cnt++);
}
0 Answers
Related