pthread question

This is a discussion on pthread question within the Linux Programming forums, part of the Platform Specific Boards category; The following idioms appear a lot in the book "Advanced Programming in the Unix Environment" by Stevens and Rago Code: ...

  1. #1
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329

    pthread question

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

    Code:
    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

    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    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.
    Code:
    //try
    //{
    	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 Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21