All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] crypto/af_alg02: use pthread_tryjoin_np() instead of pthread_kill()
Date: Fri, 16 Jul 2021 21:12:48 +0800	[thread overview]
Message-ID: <CAEemH2fdJ_N2PpdCvH8M06U-ov9G0g-tcCdCDV2wZTVWCwCR2g@mail.gmail.com> (raw)
In-Reply-To: <6e1a3663-59ea-5286-5c36-558b077184aa@bell-sw.com>

Alexey Kodanev <aleksei.kodanev@bell-sw.com> wrote:


>
> > Maybe another workaround is to define a volatile flag 'thread_complete',
> > initialize it to '0' when thread_B starts and reset to '1' while exit,
> and just
> > do a value check in the while loop of thread_A should acquire thread_B
> status.
> > Is this way a bit better?
>
> OK, why not, so something like this:
>
> diff --git a/testcases/kernel/crypto/af_alg02.c
> b/testcases/kernel/crypto/af_alg02.c
> index 0f5793c16..1fe0f3bf0 100644
> --- a/testcases/kernel/crypto/af_alg02.c
> +++ b/testcases/kernel/crypto/af_alg02.c
> @@ -18,11 +18,13 @@
>  #include "tst_test.h"
>  #include "tst_af_alg.h"
>  #include "tst_safe_pthread.h"
> +#include "tst_atomic.h"
>  #include <pthread.h>
>  #include <errno.h>
>
>  #define SALSA20_IV_SIZE       8
>  #define SALSA20_MIN_KEY_SIZE  16
> +static int completed;
>
>  static void *verify_encrypt(void *arg)
>  {
> @@ -48,6 +50,8 @@ static void *verify_encrypt(void *arg)
>                 tst_res(TPASS, "Successfully \"encrypted\" an empty
> message");
>         else
>                 tst_res(TFAIL, "read() didn't return 0");
> +
> +       tst_atomic_store(1, &completed);
>         return arg;
>  }
>
> @@ -60,7 +64,7 @@ static void run(void)
>
>         TST_CHECKPOINT_WAIT(0);
>
> -       while (pthread_tryjoin_np(thr, NULL) == EBUSY) {
> +       while (!tst_atomic_load(&completed)) {
>

+1
The atomic method is quite awesome!
-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210716/e43fce96/attachment.htm>

  reply	other threads:[~2021-07-16 13:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 10:28 [LTP] [PATCH] crypto/af_alg02: use pthread_tryjoin_np() instead of pthread_kill() Alexey Kodanev
2021-07-16  7:06 ` Li Wang
2021-07-16  9:51   ` Petr Vorel
2021-07-16 12:12     ` Alexey Kodanev
2021-07-16 12:03   ` Alexey Kodanev
2021-07-16 13:12     ` Li Wang [this message]
2021-07-16 13:21       ` Li Wang
2021-07-16 13:35         ` Alexey Kodanev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEemH2fdJ_N2PpdCvH8M06U-ov9G0g-tcCdCDV2wZTVWCwCR2g@mail.gmail.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.