Meador Inge 995a46bbfb get_nprocs: Only return explictly set cache values (BZ #16996)
The implementation of __get_nprocs uses a stactic variable to cache
the value of the current number of processors.  The caching breaks when
'time (NULL) == 0':

  $ cat nproc.c
  #include <stdio.h>
  #include <time.h>
  #include <sys/time.h>

  int main(int argc, char *argv[])
  {
    time_t t;
    struct timeval tv = {0, 0};
    printf("settimeofday({0, 0}, NULL) = %d\n", settimeofday(&tv, NULL));
    t = time(NULL);
    printf("Time: %d, CPUs: %d\n", (unsigned int)t, get_nprocs());
    return 0;
  }
  $ gcc -O3 nproc.c
  $ ./a.out
  settimeofday({0, 0}, NULL) = -1
  Time: 1401311578, CPUs: 4
  $ sudo ./a.out
  settimeofday({0, 0}, NULL) = 0
  Time: 0, CPUs: 0

The problem is with the condition used to check whether a cached
value should be returned or not:

  static int cached_result;
  static time_t timestamp;

  time_t now = time (NULL);
  time_t prev = timestamp;
  atomic_read_barrier ();
  if (now == prev)
    return cached_result;

This patch fixes the problem by ensuring that 'cached_result' has
been set at least once before returning it.
2014-06-13 14:02:04 +05:30
..
2014-06-11 12:23:35 -07:00
2014-06-09 12:53:16 -07:00
2014-05-14 11:06:36 -07:00
2014-06-09 23:22:20 -04:00
2014-05-27 15:43:45 -07:00
2014-06-09 15:54:19 -07:00
2014-06-09 13:47:38 -07:00
2014-05-16 11:17:41 -07:00
2013-06-05 20:44:03 +00:00
2014-05-16 11:47:13 -07:00
2014-03-25 15:17:08 +01:00
2014-05-08 11:27:14 -07:00
2014-05-13 09:49:20 -07:00
2014-05-13 09:49:20 -07:00
2013-08-27 10:34:16 -07:00
2014-06-12 10:32:18 -07:00