From: Richard Palethorpe <rpalethorpe@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] fzsync: revoke thread_b if parent hits an accidental break
Date: Wed, 25 Sep 2019 14:13:49 +0200 [thread overview]
Message-ID: <87d0foy3nm.fsf@rpws.prws.suse.cz> (raw)
In-Reply-To: <CAEemH2fmTHzWh=dnzFfPCrJ8-3WuXUHa_VheGj73WjcJfuiwKA@mail.gmail.com>
Hello,
Li Wang <liwang@redhat.com> writes:
> Richard Palethorpe <rpalethorpe@suse.de> wrote:
>
>>> must wrap the user supplied function. You can create a function which
>> >> accepts a pointer to some contiguous memory containing the user supplied
>> >> function
>> >> pointer and the user supplied arg pointer.
>> >>
>> >
>> > Since you have fixed the function format of thread B as void
>> *(*run_b)(void
>> > *) in tst_fzsync_pair_reset(), which means we have no need to take care
>> of
>> > the function arg pointer anymore.
>>
>> I think the function pointer signature would be 'void *(*run_b)(void)'
>> not 'void *(*run_b)(void *)'.
>>
>
> Hmm, but at least we should respect the pthread_create()? It requires the
> function prototype is ''void *(*func)(void *)'.
>
> int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
> void *(*start_routine) (void *), void *arg);
>
> We could unuse the arg in thread B, but declare the function prototype with
> parameter "void *" is no harm.
I'm not sure what you are saying. However you could do something like
this (I haven't tested it):
struct tst_fzsync_run_thread
{
void *(*run)(void *);
void *arg;
};
static void tst_fzsync_thread_wrapper(void *arg)
{
struct tst_fzsync_run_thread t = *(struct tst_fzsync_run_thread *)arg;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE);
t.run(t.arg);
}
static void tst_fzsync_pair_reset(..., struct tst_fzsync_run_thread *run_b)
{
...
if (run_b)
SAFE_PTHREAD_fCREATE(..., tst_fzsync_thread_wrapper, (void *)run_b);
...
}
Note that in any case you can't reliably cast a function pointer to a
void pointer without some magic. I am guessing wrapping it in a struct
is the clearest way to do it.
You can remove the arg altogether, but I kept it because we have a
struct anyway to wrap the function pointer.
>
>
>> I doubt any test would need the arg though, because we only use one
>> thread and can store parameters in global variables. So you could remove
>> it and update the tests.
>>
>> The user might need that arg if they are starting many threads, but for
>> now we don't have explicit support for that in the library.
>>
>
> Maybe we just need to note that in the lib document.
>
>
>> >
>> > So just like what I did in V2, the wrapper function could steal the real
>> > run_b address from pthread_create(..., wrap_run_b, run_b) parameter.
>>
>>
>> --
>> Thank you,
>> Richard.
>>
--
Thank you,
Richard.
next prev parent reply other threads:[~2019-09-25 12:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-24 10:58 [LTP] [PATCH v3] fzsync: revoke thread_b if parent hits an accidental break Li Wang
2019-09-24 12:42 ` Richard Palethorpe
2019-09-25 8:08 ` Li Wang
2019-09-25 8:53 ` Richard Palethorpe
2019-09-25 9:43 ` Li Wang
2019-09-25 12:13 ` Richard Palethorpe [this message]
2019-09-26 5:48 ` Li Wang
2019-09-26 9:25 ` Richard Palethorpe
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=87d0foy3nm.fsf@rpws.prws.suse.cz \
--to=rpalethorpe@suse.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox