[Bug 1894] missing a tick in _Timespec_To_ticks

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Tue Aug 9 13:54:47 UTC 2011


https://www.rtems.org/bugzilla/show_bug.cgi?id=1894

--- Comment #3 from Jie Liu <lj8175 at gmail.com> 2011-08-09 08:54:47 CDT ---
This is a test case:

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>

void *POSIX_Init( void *arg ){
  pthread_cond_t        cond;
  pthread_mutex_t       mutex;
  struct timespec       to;
  struct timeval        tv;
  int                   i;

  pthread_cond_init(&cond,NULL);
  pthread_mutex_init(&mutex,NULL);

  for(i=0;i<10;i++){
    gettimeofday (&tv, NULL);
    to.tv_sec=tv.tv_sec;
    to.tv_nsec=tv.tv_usec*1000+10000000; //add 10 ms from now
    if (to.tv_nsec>1000000000){
      to.tv_sec++;
      to.tv_nsec-=1000000000;
    }

    pthread_mutex_lock(&mutex);
    pthread_cond_timedwait(&cond,&mutex,&to); //sleep 10 ms
    pthread_mutex_unlock(&mutex);

    gettimeofday (&tv, NULL);
    printf("%d: sleep %d ns\n",i,
(tv.tv_sec-to.tv_sec)*1000000000+tv.tv_usec*1000-to.tv_nsec+10000000);
  }

  exit(0);
}


/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_MICROSECONDS_PER_TICK 1000
#define CONFIGURE_TICKS_PER_TIMESLICE   50

#define CONFIGURE_MAXIMUM_POSIX_THREADS 50
#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 100
#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES  100
#define CONFIGURE_MAXIMUM_POSIX_KEYS 300
#define CONFIGURE_MAXIMUM_POSIX_TIMERS 100
#define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 100
#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 100
#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 100
#define CONFIGURE_MAXIMUM_TASK_VARIABLES (2 * 40)
#define CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE (4*1024 * 1024)
#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (1024 * 1024)

#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20

#define CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY TRUE
#define CONFIGURE_STACK_CHECKER_ENABLED TRUE

#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/* end of file */

-- 
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.



More information about the bugs mailing list