[Date Prev][Date Next]
Re: (ITS#3950) sched_yield() considered harmful
Howard Chu wrote:
> email@example.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) (184.108.40.206)
>> Calling sched_yield() makes slapd slow down considerably
>> under load since kernel 2.6.
> 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
// Bernardo Innocenti - Develer S.r.l., R&D dept.