Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why were threads never included as part of the C++ standard?

Why is it that threads were never included as part of the C++ standard originally? Did they not exist when C++ standard was first created?

like image 465
Tony The Lion Avatar asked Oct 18 '10 13:10

Tony The Lion


People also ask

Do we have threads in C?

Each part of such a program is called a thread, and each thread defines a separate path of execution. C does not contain any built-in support for multithreaded applications. Instead, it relies entirely upon the operating system to provide this feature.

What do threads never share?

Note: stack and registers can't be shared among the threads. Each thread has its own stack and registers.

How do threads communicate with each other in C?

producer and consumer threads should capture each other's tid. producer on producing can send: pthread_kill(consumerID, SIGUSR1); consumer is setup with the signal handler for SIGUSR1, and can retrieve the produced result from the common std::queue saved by pthread_setspecific().


2 Answers

I think the main reasons are

  • specifying threading behavior into the language needs a lot of work and understanding, which nobody had available back then
  • nobody had a great idea about a good threading API, and there was no one existing library that seemed good enough to be used as a base for further work
  • the standardization committee was swamped with enough of other work (like incorporating the STL into the standard library)
  • that standard was late as it was; it took more than ten years for the first version to emerge, with quite a lot delay due to "last-minute changes" (std::auto_ptr, STL), and I think the main feeling was to better have something out sooner than to keep waiting for an infinitively delayed perfect standard; I think back then most people didn't think it would take so long for the next version to get finalized

After the standard was ratified, boost was founded by members of the library working group as a testbed for libraries which were desirable to have in the std lib but for which there wasn't enough time to make it for the final version. There, much of the work needed for adding threading support to C++ (namely inventing a good threading library) was done.

like image 116
sbi Avatar answered Oct 21 '22 19:10

sbi


The current Standard is from 1998. There were different thread implementations, and there wasn't the body of experience with using threads that there is twelve years later. If C++ had had a standardized thread library, it would likely have worked poorly with some common thread implementations, and might well have been difficult to adapt in the future.

It's twelve years later now, and we know a whole lot more about how threads are used, and the more widespread use created more interest in standardizing them, so the upcoming C++ standard (which I hope will be official in 2011) will have a section on threads in the library.

like image 45
David Thornley Avatar answered Oct 21 '22 19:10

David Thornley