public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/16996] New: get_nprocs caching breaks when 'time (NULL) == 0'
@ 2014-05-28 21:29 meadori at codesourcery dot com
  2014-06-13 10:50 ` [Bug libc/16996] " cvs-commit at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: meadori at codesourcery dot com @ 2014-05-28 21:29 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16996

            Bug ID: 16996
           Summary: get_nprocs caching breaks when 'time (NULL) == 0'
           Product: glibc
           Version: 2.21
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: meadori at codesourcery dot com
                CC: drepper.fsp at gmail dot com

Currently 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

I know the circumstances of setting the time of day to (0, 0) are odd,
but it still shouldn't be so trivial to break the caching.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-16 16:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-28 21:29 [Bug libc/16996] New: get_nprocs caching breaks when 'time (NULL) == 0' meadori at codesourcery dot com
2014-06-13 10:50 ` [Bug libc/16996] " cvs-commit at gcc dot gnu.org
2014-06-13 10:51 ` siddhesh at redhat dot com
2014-06-16 16:32 ` fweimer at redhat dot com

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 read-only IMAP folder(s) and NNTP newsgroup(s).