# Chapter 17: Library Introduction

Chapter 17 is actually a list of definitions and descriptions used in the following chapters of the Standard when describing the actual library. Here, we use "Introduction" as an introduction to the GNU implementation of the ISO Standard C++ Library.

# Contents

- The Standard C++ header files
- Thread-safety
- `<foo>` vs `<foo.h>`
- Porting-howto

## The Standard C++ header files

The Standard C++ Library specifies 50 header files that must be available to all hosted implementations. Actually, the word "files" is a misnomer, since the contents of the headers don't necessarily have to be in any kind of external file. The only rule is that when you `#include` a certain header, the contents of that header, as defined by the Standard, become available to you, no matter how.

The names of the headers can be easily seen in `testsuite/17_intro/headers.cc`, which is a small testbed we use to make certain that the headers all compile and run.

## Thread-safety

This is a thorny issue that gets brought up on the libstdc++-v3 and gcc mailing lists on a regular basis (probably by a cron job). This entry will mention a very little bit about the general MT issues with libstdc++. The latest status and quick notes will be in FAQ 5.6. Some discussion about threadsafe containers will be in section 6.8 (the HOWTOs on containers).

The libstdc++ code (all of it, not just the containers) has been designed so that thread-safety will be easily possible. The first (!) problem is finding a fast method of implementation portable to all platforms. A minor problem that pops up every so often is different interpretations of what "thread-safe" means for a library (not a general program). We currently use the same definition that SGI uses for their STL subset.

A recent journal article has described "atomic integer operations," which would allow us to, well, perform updates on integers atomically, and without requiring an explicit mutex lock. This appears promising, but the major difficulty is that these operations "may not be available on all systems, and if they are, may have different interfaces." [quoting from mailing list messages]

Here is a small link farm to threads (no pun) in the mail archives that discuss the threading problem. Each link is to the first relevent message in the thread; from there you can use "Thread Next" to move down the thread. This farm is in latest-to-oldest order.

Here are discussions that took place before the current snapshot; they are still relevant and instructive.

- One way of preventing memory leaks by the old default memory allocator in multithreaded code is discussed here.
- This thread concerns strings.
- So does this one. This initial message also refers to another thread in the GCC mailing list...
- which is here, and goes on for some time. Ironically, the initial message in this thread also mentions another threading thread...
- beginning here, and talking about pthreads. (Note that a much more recent message from the first thread in this list notes that pthreads should not be used as a starting point for making libstdc++ threadsafe.)
- This message, this one, and this one are the tops of related threads (all within the same time period) discussing threading and the IO library. Much of it is dealing with the C library, but C++ is included as well.

This section will be updated as new and interesting issues come to light.

Return to top of page or to the FAQ.

## `<foo>` vs `<foo.h>`

The new-style headers are fully supported in libstdc++-v3. The compiler itself fully supports namespaces. However, at the moment, the compiler treats std:: as the global namespace by default.

For those of you new to ISO C++98, no, that isn't a typo, the headers really have new names. Marshall Cline's C++ FAQ Lite has a good explanation in item [25.4].

Return to top of page or to the FAQ.

Comments and suggestions are welcome, and may be sent to Phil Edwards or Gabriel Dos Reis.
$Id: howto.html,v 1.3 2000/05/03 16:11:02 pme Exp $