Thread: pthread question

  1. #1
    Join Date
    May 2007
    Berkeley, CA

    pthread question

    The following idioms appear a lot in the book "Advanced Programming in
    the Unix Environment" by Stevens and Rago

    int err
    sigset_t oldmask;
    pthread_t tid;
    if ((err = pthread_sigmask(SIG_BLOCK, &mask, &oldmask)) ! = 0 )
      err_exit(err, "SIG_BLOCK error");
    err = pthread_create(&tid, NULL, thrd_fn, 0);
    if(err != 0)
       err_exit(err, "can't create thread");
    The question is why don't do something like

    if((err = pthread_create(&tid, NULL, thrd_fn, 0)) != 0)
       err_exit(err, "can't create thread");
    like what they do for pthread_sigmask()?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You'd have to ask them about their coding standard
    But both are functionally equivalent, so I can't see a reason to be different.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    Looks like the book-writers did a copy-and-paste job to put together those examples. You are seeing a mixture of two styles, that's all.
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Pthread Hell
    By matott in forum Linux Programming
    Replies: 1
    Last Post: 04-10-2005, 05:59 AM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. pthread question
    By rotis23 in forum Linux Programming
    Replies: 10
    Last Post: 04-07-2004, 02:57 AM
  4. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM