[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: (ITS#3950) sched_yield() considered harmful

Howard Chu wrote:
> bernie@develer.com wrote:
>> Full_Name: Bernardo Innocenti
>> Version: 2.2.26 to 2.3.5, possibly others
>> OS: Linux
>> URL: ftp://ftp.openldap.org/incoming/
>> Submission from: (NULL) (
>> Calling sched_yield() makes slapd slow down considerably
>> under load since kernel 2.6.
>> See:
>>   http://www.ussg.iu.edu/hypermail/linux/kernel/0508.2/0516.html
> Thanks for pointing this out. I'm not sure why we ever used
> sched_yield() in the first place, it was known to cause headaches on the
> Solaris build as well. We should probably leave it as a last resort, and
> prefer pthread_yield() instead.

In glibc 2.3, pthread_yield() is just a stub for sched_yield().

I don't quite understand why OpenLDAP ever needs to poll with
pthread_yield().  Instead of spinning on shared variables,
locking should be done using pthread's synchronization primitives,
most of which are implemented efficiently on Linux with futex().

If OpenLDAP must remain compatible with OSes where pthreads aren't
available, locking can be abstracted in portability functions like
sched_yield() was.

  // Bernardo Innocenti - Develer S.r.l., R&D dept.
\X/  http://www.develer.com/