[cpp-threads] Re: Thread API interface tweaks

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Aug 30 11:40:03 BST 2006


"Alexander Terekhov" <alexander.terekhov at gmail.com> wrote:
> > Lawrence Crowl wrote:
> >
> > > Most large applications live in a multi-language world, and like it or
> > > not, C is the common glue that binds them together.  Therefore, I
> > > would like to see the C interface for manipulating a thread - yield,
> > > sleep, mutexes, etc.  I do not think we can reliably leave that task
> > > to later.
> >
> > I "vote" for <pthread.h> and <sched.h> being that C interface. This saves a
> > lot of standardization work. :-)
> 
> I second that. All what's needed is a section showing how that C
> legacy stuff can be implemented using <thread> akin to (quoting C++
> TR, with annotations added):

Aargh!  Haven't you LOOKED at that mess?  You clearly haven't tried
using them for "threads for performance".

The "thread control" aspects of POSIX threads are not as totally broken
as the "memory model" aspects, but are broken beyond the ability to
use them either reliably or portably.  Even programming as the system
administrator (i.e. being prepared and capable to reconfigure and
reboot to enable my code to work), I couldn't get them to fly.  And
I have spoken to nobody else who has succeeded - and damn few who have
tried.

So <pthread.h> has its flaws, but the above approach would at least
be feasible.  It could certainly be used as a starting point, but
should definitely not be assumed as is.

<sched.h> and related sections is a disaster on wheels.  It doesn't
even provide the most BASIC facilities for application threading, such
as the ability for one thread to yield in favour of another (in the
same process), or the ability to say "schedule ALL of the threads in
this set on separate CPUs, simultaneously, or suspend the lot".

And, despite any impression to the contrary, <sched.h> merely provides
hints to the PROCESS scheduler, which (in my experience) doesn't obey
them anyway.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679



More information about the cpp-threads mailing list