Problem with pThread sync issue

前端 未结 5 1082
温柔的废话
温柔的废话 2020-12-29 00:27

I am facing a sync issue with pthread. threadWaitFunction1, is a thread wait function. I expect line no. 247 flag = 1 to be executed only after 243-246 has fini

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 01:10

    Just for everyone's info:

    What i could not achieve using pthread_cond_timedwait(&timerCond, &timerMutex, ptr); i have achieved using usleep( ), usleep takes timespec structure where we can specify the wait period using seconds and nanoseconds, and my purpose is solved.

    So what does the pthread_cond_timedwait(&timerCond, &timerMutex, ptr); make sense for?? I am surprised, as this API is expected to make the calling thread wait, fo that condition to satisfy, but it seems that processor jumps to next instruction as an optimisation measure, and does not wait foer the condition to satisfy.

    But still my problem remains the same, as to why, pthread_cond_timedwait(&timerCond, &timerMutex, ptr); should not make the calling thread wait?

    It seems i wasted a day behind this API: pthread_cond_timedwait( )

提交回复
热议问题