Branch: Tag:

2009-03-13

2009-03-13 16:22:31 by Martin Stjernholm <mast@lysator.liu.se>

More robust way to measure time slices for yielding when clock(2) is used.
This fixes some cases with starving on e.g. linux.

Rev: src/pike_threadlib.h:1.68
Rev: src/threads.c:1.275

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: threads.c,v 1.274 2009/01/26 10:15:06 grubba Exp $ + || $Id: threads.c,v 1.275 2009/03/13 16:22:31 mast Exp $   */      #include "global.h"
347: Inside #if defined(USE_CLOCK_FOR_SLICES)
  PMOD_EXPORT ptrdiff_t thread_storage_offset;   #ifdef USE_CLOCK_FOR_SLICES   PMOD_EXPORT clock_t thread_start_clock = 0; + PMOD_EXPORT THREAD_T last_clocked_thread = 0;   #endif      #ifdef PIKE_DEBUG
925:    }    }   #elif defined (USE_CLOCK_FOR_SLICES) + #ifdef PIKE_DEBUG +  if (last_clocked_thread != th_self()) +  Pike_fatal ("Stale thread %08lx in last_clocked_thread (self is %08lx)\n", +  (unsigned long) last_clocked_thread, (unsigned long) th_self()); + #endif    if (clock() - thread_start_clock < (clock_t) (CLOCKS_PER_SEC / 20))    return;   #else
956:    THREADS_DISALLOW();      #ifdef USE_CLOCK_FOR_SLICES -  /* Must set the base time for the slice here since clock() returns -  * thread local time. */ +  /* If we didn't yield then give ourselves a new time slice. If we +  * did yield then thread_start_clock is the current clock anyway +  * after the thread swap in. */    thread_start_clock = clock(); -  + #ifdef PIKE_DEBUG +  if (last_clocked_thread != th_self()) +  Pike_fatal ("Stale thread %08lx in last_clocked_thread (self is %08lx)\n", +  (unsigned long) last_clocked_thread, (unsigned long) th_self());   #endif -  + #endif       DEBUG_CHECK_THREAD();   }