On May 19, 6:45 pm, Szabolcs Ferenczi <
[email protected]>
wrote:
On May 18, 11:00 pm, Szabolcs Ferenczi <
[email protected]>
wrote:
since you were trolling in the other discussion
thread in "Threading in new C++ standard" too,
...
that threads are not
going to be included at the language level in C++0x. You were
corrected there by people taking part in C++0x standardisation.
And that is simply a lie.
Is it?
[...]
How about this:
<quote>
23. Pete Becker View profile More options Apr 20, 7:04 pm
On 2008-04-20 12:36:50 -0400, James Kanze <
[email protected]>
said:
There was never a proposal for introducing the
threading API at the language level, however; that just seems
contrary to the basic principles of C++, and in practice, is
very limiting and adds nothing.
There actually was a proposal for threading at the language level:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1875.html.
...
</quote>
http://groups.google.com/group/comp.lang.c++/msg/1ea5fdf80fd7f461
Q.E.D.
Hmmmm...
"threading API at the language level" != "threading at the language
level"
"language level" != "API"
C++ will have threading at the language level, but you will not be
able to
access the threading primitives via keywords;
Then it is not at the language level. Do you know at all what language
is?
*sigh*. We have been trying to explain it painfully to you for a long
time.
In C++ land, the "C++ language" is the standard defined in the
ISO/IEC 14882:2003 document, no more no less.
This document include both a keyword based interface (also called
core) and a library based interface (also called standard library),
both interfaces together make the C++ language (a freestanding
implementation my lack part but not all of the standard library).
Notice that the distinction between core and library is purely
a matter of convenience, and is more due to historical reasons
than anything (if C++ were rewritten today, core would be even
smaller).
Just because some parts are classified as "library" it doesn't
means that it must actually be implemented as a library:
std::vector for all purposes might as well be a special keyword:
same thing for std::string.
Sometimes the distinction between the core and library part
is very fuzzy: consider placement new: it is for all intent
and purposes a very primitive builtin, but in theory it should
be defined in the <new> header. Or the builting typeid, which
needs header <type_info> for support. The new range based
for loop, a variant of the classic 'for' also need a support
header.
But I'm sure this won't convince you. Let's take another route:
think about a language like java, which has explicit
synchronized {} blocks. Certainly, by all definitions, this
is language support for threading (even if I'm sure it doesn't fit
your vision of good language threading support).
Let's consider a little variant of java/c++ hybrid with a
builtin mutex type, where the synchronized block take
the mutex explicitly as a parameter (instead of implicitly
like in java), and obvious semantics.
mutex m;
...
synchronized(m) {
// do something in mutual exclusion
}
So far so good.
An user is free to do this:
class my_mutex {
friend my_synchronized;
private:
mutex m;
};
template<template Body>
void my_synchronized(Body b, my_mutex m) {
synchronized(m.m) {
b();
}
}
Use them like this:
my_mutex m;
my_synchronized(
lambda()
{ /* body in mutual exclusion here */ }
, m
);
So far, so good, certainly threading is still at the language level.
Let's say that, for whatever reasons, the language designers, liked
both my_mutex and my_synchronized so much that decided that these
are the primary meaning to access synchronization primitives, and
eventually relegated mutex and synchronized as implementation
detail and no longer accessible to user code.
Would this remove suddenly threading support from the language?
I'm sure that you can come up with some definition which will
support your view, but it will be a very narrow minded one (
which will value syntactic sugar more than semantics)
This is exactly the situation in C++: my_mutex is spelled
std::mutex (and other beasts), and, instead of my_synchronized,
we use scoped locks, as higher order functions are a bit
cumbersome in C++.
What matters are the semantics, not the syntactic sugar. C++0x
certainly has well defined multi threaded semantics, even if
the syntax might not have all the bell and whistles of other
languages.
In C++03, there were still no pure library based thread packages:
posix, openmp, even win32, all define a dialect
of C++ which add thread semantics to C++ (actually C).
Unfortunately, so far, all this bolt on additions have been
less than perfect, bug prone, and lacking in corner areas.
C++0x try to fix all these problems, in part by standardizing
existing work, in part by explicitly specifying which threaded
programs are legal, and finally expanding the state of the art
(of C++) a bit by adding atomic primitives.