Re: How to implement a thread library in C++

Laurence Finston <>
2 Jun 2005 01:02:04 -0400

          From comp.compilers

Related articles
How to implement a thread librar in C++ (DeltaOne) (2005-05-31)
Re: How to implement a thread library in C++ (Laurence Finston) (2005-06-02)
Re: How to implement a thread library in C++ (Aaron Gray) (2005-06-02)
| List of all articles for this month |

From: Laurence Finston <>
Newsgroups: comp.compilers
Date: 2 Jun 2005 01:02:04 -0400
Organization: GWDG, Goettingen
References: 05-05-229
Keywords: C++, parallel
Posted-Date: 02 Jun 2005 01:02:04 EDT

On Wed, 31 May 2005, DeltaOne wrote:

> I want to build a thread library in C++. Can any one give me some
> reference for this or tell how to design it?

What exactly is your purpose in writing this library? Is it intended
to be POSIX-compliant? How low-level is it intended to be? Is it
intended to be used with a single operating system or with multiple
operating systems? Are these operating systems programmed in C++? Is
this a research project or do you just want to combine the use of
threads with the styles of programming suppported by C++?

If your thread library is intended to be POSIX-compliant, you will
need a copy of the standard. If it's not POSIX-compliant, you may
have difficulty finding users. My favorite book on threads (not that
I'm an expert on thread literature) is David Butenhof's _Programming
with POSIX Threads_. I think this would be a good place to start.

The LinuxThreads library is part of the GNU C++ Standard Library
(libstdc++): ''. Unless you
really want to write a threads library from scratch, I think it's
reasonable to just wrap the data types and functions supplied by the
LinuxThreads library (or some other threads library) in C++ data types
and functions. This is what I do in GNU 3DLDF. For example, I've
defined 'struct Cond_Var_Type' to wrap the type 'pthread_cond_t',
'struct Mutex_Type' to wrap 'pthread_mutex_t', and 'struct
Thread_Info_Type' to wrap 'pthread_key_t'. These 'structs' have
member functions that call the pthreads functions that take pointers
to objects of the pthreads types as arguments. It would be perfectly
reasonable to just use the pthreads data types and functions as-is; I
just find my way more convenient. I _do not_ believe in the innate
superiority of C++ over C.

Laurence Finston

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.