linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* pthread_create
@ 2020-06-15 21:40 Jonny Grant
  0 siblings, 0 replies; only message in thread
From: Jonny Grant @ 2020-06-15 21:40 UTC (permalink / raw)
  To: Michael Kerrisk, linux-man

Hello mtk,

https://www.man7.org/linux/man-pages/man3/pthread_create.3.html

This has a good example I saw, what do you think about replacing these pre-processor macros containing do {} while(0) with regular functions?

Something like this:

void handle_error_en(int en, const char * const msg)
{
      errno = en;
      perror(msg);
      exit(EXIT_FAILURE);
}

void handle_error(const char * const msg)
{
      perror(msg);
      exit(EXIT_FAILURE);
}


Although I don't think errno is such a good idea. so I'd probably write:

void handle_error_en(int en, const char * const msg)
{
      fprintf(stderr, "%s: %s\n", msg, strerror(en));
      exit(EXIT_FAILURE);
}

I'd also suggest adding the command line to compile $ cc -Wall -pthread -o threads threads.c

Regards, Jonny

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-15 21:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 21:40 pthread_create Jonny Grant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).