Bug 156800 - Protect against spurious wakeups
Summary: Protect against spurious wakeups
Status: REPORTED
Alias: None
Product: kdemultimedia
Classification: Miscellaneous
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Multimedia Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-27 19:36 UTC by Markus Elfring
Modified: 2022-12-02 17:37 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Elfring 2008-01-27 19:36:11 UTC
Version:            (using KDE 4.0.0)

I have seen that no loop is used around the call of the function "pthread_cond_wait" in the function "cdda_fct_play".
http://websvn.kde.org/trunk/KDE/kdemultimedia/libkcompactdisc/wmlib/cdda.c?revision=756952&view=markup

Would you like to reuse anything from my message on the topic "spurious wakeup"?
http://groups.google.de/group/comp.programming.threads/msg/bb8299804652fdd7

I have got doubts about your handling of condition variables.
http://en.wikipedia.org/wiki/Monitor_%28synchronization%29#Condition_variables
Comment 1 Alex Kern 2008-01-30 23:11:34 UTC
Hi, I would like to make clear...

man pthread_cond_wait

The pthread_cond_timedwait() and pthread_cond_wait() functions may fail if:
  EINVAL The value specified by cond, mutex, or abstime is invalid.
  EINVAL Different mutexes were supplied for concurrent pthread_cond_timedwait() or pthread_cond_wait() operations on the same condition  variable.
  EPERM  The mutex was not owned by the current thread at the time of the call.


  These functions shall not return an error code of [EINTR].


!!! Also it's not allowed for pthread to return if wakeup is occurs. !!!
Comment 2 Markus Elfring 2008-02-01 09:10:38 UTC
> Also it's not allowed for pthread to return if wakeup is occurs.

Your expectation is wrong for the POSIX interface.
http://www.opengroup.org/onlinepubs/009695399/functions/pthread_cond_wait.html
"Spurious wakeups from the pthread_cond_timedwait() or pthread_cond_wait() functions may occur."
Comment 3 Markus Elfring 2009-05-31 13:03:51 UTC
I recommend to add a loop for the predicate check. When will the implementation of the function "cdda_fct_play" be completed together with error detection and corresponding exception handling?
http://websvn.kde.org/trunk/KDE/kdemultimedia/libkcompactdisc/wmlib/cdda.c?revision=826360&view=markup
Comment 4 Alex Kern 2009-06-01 22:31:39 UTC
Hi, feel free to propose a patch.
Greetings
Alex
Comment 5 Markus Elfring 2009-06-01 22:38:42 UTC
I have got the impression that it might be hard to achieve consensus on an acceptable patch in the combination with proper error handling. I would also need a clarification for the predicate that should be waited for in a loop.
Comment 6 Michael Pyne 2009-06-02 01:26:24 UTC
Markus, it seems to me that the "wakeup" local variable in cdda_fct_read() is the predicate you would need.  Of course the variable would have to be moved to a more shared namespace (wm_drive?) to make that work.
Comment 7 Markus Elfring 2009-06-02 21:40:32 UTC
Your suggestion is not clear for me because I do not see so far how a useful wait condition would be derived from the input parameter "arg/wm_drive". Which predicate would be meaningful?

By the way:
I wonder why the global variable "blks_mutex" is not initialised in this source file. I would expect calls to the function "pthread_mutex_init" for each array element.
Comment 8 Andrew Crouthamel 2018-11-02 23:01:41 UTC
Dear Bug Submitter,

This bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version? I am setting the status to NEEDSINFO pending your response, please change the Status back to REPORTED when you respond.

Thank you for helping us make KDE software even better for everyone!
Comment 9 Markus Elfring 2018-11-03 09:56:01 UTC
(In reply to Andrew Crouthamel from comment #8)

It find that the implementation of the function “cdda_fct_play” will need further adjustments (if the affected software library is still relevant today).
https://github.com/KDE/libkcompactdisc/blob/4a465e259a62ebd6b1c4993e5821968777aeda6d/src/wmlib/cdda.c#L287
Comment 10 Justin Zobel 2022-12-02 01:22:52 UTC
Thank you for reporting this issue in KDE software. As it has been a while since this issue was reported, can we please ask you to see if you can reproduce the issue with a recent software version?

If you can reproduce the issue, please change the status to "REPORTED" when replying. Thank you!
Comment 11 Markus Elfring 2022-12-02 17:37:40 UTC
(In reply to Justin Zobel from comment #10)
Would you like to help any more with a proper source code review?
https://github.com/KDE/libkcompactdisc/blob/1771e180811d8a3f87f3e1a0003ab0360564c021/src/wmlib/cdda.c#L287