All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Kodanev <alexey.kodanev@oracle.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/2] lib: add safe_pthread_create() & safe_pthread_join()
Date: Thu, 7 Apr 2016 19:42:53 +0300	[thread overview]
Message-ID: <57068E0D.4090809@oracle.com> (raw)
In-Reply-To: <20160407113531.GA16682@rei>

Hi,
On 04/07/2016 02:35 PM, Cyril Hrubis wrote:
> Hi!
>> +int safe_pthread_join(const char *file, const int lineno,
>> +		      pthread_t thread_id, void **retval)
>> +{
>> +	int rval;
>> +
>> +	rval = pthread_join(thread_id, retval);
>> +
>> +	if (rval) {
>> +		tst_brk_(file, lineno, TBROK,
>> +			 "pthread_join(%lu,%p) failed: %s", thread_id, retval,
>> +			 tst_strerrno(rval));
> Technically the thread_id does not need to be numeric type, POSIX
> defines it as a opaque, may be structure as well.

We could print in hex like this:

if (rval) {
     unsigned int i;
     unsigned char *ptr = (unsigned char *)&thread_id;
     size_t tid_size = sizeof(thread_id);
     char buf[tid_size * 2 + 1];

     for (i = 0; i < tid_size; ++i)
         sprintf(buf + i * 2, "%02x", ptr[i]);

     tst_brk_(file, lineno, TBROK,
              "pthread_join(%s,%p) failed: %s", buf, retval, ...);
}

But bytes might be in different order due to endianness,
supposing we compare this value with "%lx", e.g. on x86_64

00971fe3257f0000 vs 7f25e31f9700 (%lx)

What do you think?

Thanks,
Alexey

>
> But on the other hand I doubt that there is a Linux libc implementation
> that actually defines it to be anything else than long int.
>> +	}
>> +
>> +	return rval;
>> +}
> Otherwise this looks fine.
>


  reply	other threads:[~2016-04-07 16:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-07  8:10 [LTP] [PATCH v2 1/2] lib: add safe_pthread_create() & safe_pthread_join() Alexey Kodanev
2016-04-07  8:10 ` [LTP] [PATCH v2 2/2] syscalls/fcntl: add new test for open file description locks Alexey Kodanev
2016-04-07 12:38   ` Cyril Hrubis
2016-04-12 10:01   ` Alexey Kodanev
2016-04-07 11:35 ` [LTP] [PATCH v2 1/2] lib: add safe_pthread_create() & safe_pthread_join() Cyril Hrubis
2016-04-07 16:42   ` Alexey Kodanev [this message]
2016-04-11 14:46     ` Cyril Hrubis
2016-04-12  9:21       ` 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=57068E0D.4090809@oracle.com \
    --to=alexey.kodanev@oracle.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.