pthread_cond_timedwait dosn't work

Hello,

the timeout behavior of the pthread_cond_timedwait doesn’t work as
specified.
The call returns immediately with ETIMEDOUT … regardless what
timeout value is provided.

Target is running Neutrino 2.0C / PPC.

Here is a trace of my gdb session:


557 if(buf_n == 0)
558 {
559 // setup read timeout
(gdb)
560 interv = (double)(msg->timeout * 0.1); // in sec
561 abs_time.tv_sec = (int)floor(interv);
562 abs_time.tv_nsec = (int)((interv - floor(interv)) *
1000000000L);
563
564 pthread_mutex_lock(&read_mutex);
565 if(read_flag == 0)
566 {
567 ret = pthread_cond_timedwait(&read_cond,
&read_mutex, &abs_time);
568 }
569 read_flag = 0;
(gdb) b 569
Breakpoint 3 at 0x4804296c: file handle.c, line 569.
(gdb) c
Continuing.

----> call terminates immediately!

Breakpoint 3, process_io_read (msg=0x47fbef88) at handle.c:569
569 read_flag = 0;
(gdb) print ret
$1 = 260
(gdb) print abs_time
$2 = {tv_sec = 20, tv_nsec = 0}
(gdb)


Seems to be a bug … is there a patch available?

Armin

Here is the patch you need:

561 abs_time.tv_sec = time(NULL) + (int)floor(interv);
^^^^^^^^^^

Little bit non-intuitive but that’s what docs say. Third parameter is
absolute time. And the example in pthread_cond_timedwait() docs shows that
too.

Cheers,

  • Igor “if you’ve tried everything already and it still doesn’t work, try
    reading docs”.

“Armin Steinhoff” <A-Steinhoff@web_.de> wrote in message
news:3A97C336.A9D14C45@web_.de…

Hello,

the timeout behavior of the pthread_cond_timedwait doesn’t work as
specified.
The call returns immediately with ETIMEDOUT … regardless what
timeout value is provided.

Target is running Neutrino 2.0C / PPC.

Here is a trace of my gdb session:


557 if(buf_n == 0)
558 {
559 // setup read timeout
(gdb)
560 interv = (double)(msg->timeout * 0.1); // in sec
561 abs_time.tv_sec = (int)floor(interv);
562 abs_time.tv_nsec = (int)((interv - floor(interv)) *
1000000000L);
563
564 pthread_mutex_lock(&read_mutex);
565 if(read_flag == 0)
566 {
567 ret = pthread_cond_timedwait(&read_cond,
&read_mutex, &abs_time);
568 }
569 read_flag = 0;
(gdb) b 569
Breakpoint 3 at 0x4804296c: file handle.c, line 569.
(gdb) c
Continuing.

----> call terminates immediately!

Breakpoint 3, process_io_read (msg=0x47fbef88) at handle.c:569
569 read_flag = 0;
(gdb) print ret
$1 = 260
(gdb) print abs_time
$2 = {tv_sec = 20, tv_nsec = 0}
(gdb)


Seems to be a bug … is there a patch available?

Armin

snip

Cheers,

  • Igor “if you’ve tried everything already and it still doesn’t work, try
    reading docs”.

Sounds like some kind of sinister plot to me. :slight_smile:

Dean Douthat <ddouthat@faac.com> wrote:
:>

:> Cheers,
:> - Igor “if you’ve tried everything already and it still doesn’t work, try
:> reading docs”.
:>

: Sounds like some kind of sinister plot to me. :slight_smile:

Stop that kind of talk! I was going to tell Igor that he made my day. :slight_smile:


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Igor Kovalenko wrote:

Here is the patch you need:

561 abs_time.tv_sec = time(NULL) + (int)floor(interv);
^^^^^^^^^^

Little bit non-intuitive but that’s what docs say. Third parameter is
absolute time. And the example in pthread_cond_timedwait() docs shows that
too.

Thanks.

Cheers,

  • Igor “if you’ve tried everything already and it still doesn’t work, try
    reading docs”.

Depends on the docs :slight_smile: … I use the following:

http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads/MAIN.html

Armin


“Armin Steinhoff” <A-Steinhoff@web_.de> wrote in message
news:3A97C336.A9D14C45@web_.de…

Hello,

the timeout behavior of the pthread_cond_timedwait doesn’t work as
specified.
The call returns immediately with ETIMEDOUT … regardless what
timeout value is provided.

Target is running Neutrino 2.0C / PPC.

Here is a trace of my gdb session:


557 if(buf_n == 0)
558 {
559 // setup read timeout
(gdb)
560 interv = (double)(msg->timeout * 0.1); // in sec
561 abs_time.tv_sec = (int)floor(interv);
562 abs_time.tv_nsec = (int)((interv - floor(interv)) *
1000000000L);
563
564 pthread_mutex_lock(&read_mutex);
565 if(read_flag == 0)
566 {
567 ret = pthread_cond_timedwait(&read_cond,
&read_mutex, &abs_time);
568 }
569 read_flag = 0;
(gdb) b 569
Breakpoint 3 at 0x4804296c: file handle.c, line 569.
(gdb) c
Continuing.

----> call terminates immediately!

Breakpoint 3, process_io_read (msg=0x47fbef88) at handle.c:569
569 read_flag = 0;
(gdb) print ret
$1 = 260
(gdb) print abs_time
$2 = {tv_sec = 20, tv_nsec = 0}
(gdb)


Seems to be a bug … is there a patch available?

Armin

Armin Steinhoff wrote:

  • Igor “if you’ve tried everything already and it still doesn’t work, try
    reading docs”.

Depends on the docs > :slight_smile: > … I use the following:

http://www.llnl.gov/computing/tutorials/workshops/workshop/pthreads/MAIN.html

Perhaps you have some reason to prefer some tutorial to official docs.
Anyway, the O’Reilly ‘Pthreads Programming’ book says the same thing as
QNX docs, but in even more clear manner, which leaves no doubts at all
about meaning of 3rd parameter. If you haven’t read it yet, I’d highly
recommend it.

  • igor