[pulseaudio-discuss] [PATCH] thread-test: fix deadlock

Alexander E. Patrakov patrakov at gmail.com
Mon Jan 23 08:59:53 UTC 2017


2017-01-23 13:38 GMT+05:00 Tanu Kaskinen <tanuk at iki.fi>:
> If we set magic_number to zero, the code will deadlock, because the
> thread that is waiting for us to set magic_number to non-zero will
> never progress.
>
> The problem was reported here:
> https://lists.freedesktop.org/archives/pulseaudio-discuss/2017-January/027368.html
> ---
>  src/tests/thread-test.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

I have looked at the fix and believe that it's correct.

>
> diff --git a/src/tests/thread-test.c b/src/tests/thread-test.c
> index 72f21770e..0c83e67e0 100644
> --- a/src/tests/thread-test.c
> +++ b/src/tests/thread-test.c
> @@ -115,7 +115,10 @@ START_TEST (thread_test) {
>      for (k = 0; k < 100; k++) {
>          pa_assert(magic_number == 0);
>
> -        magic_number = (int) rand() % 0x10000;
> +        /* There's a thread waiting for us to change magic_number to a non-zero
> +         * value. The "+ 1" part ensures that we don't accidentally set
> +         * magic_number to zero here. */
> +        magic_number = (int) rand() % 0x10000 + 1;
>
>          pa_log_info("iteration %i (%i)", k, magic_number);
>
> --
> 2.11.0
>
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss



-- 
Alexander E. Patrakov


More information about the pulseaudio-discuss mailing list