473,898 Members | 4,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading in new C++ standard

Rather than create a new way of doing things:
http://www.open-std.org/jtc1/sc22/wg...008/n2497.html
why not just pick up ACE into the existing standard:
http://www.cse.wustl.edu/~schmidt/ACE.html
the same way that the STL (and subsequently BOOST) have been subsumed?
Since it already runs on zillions of platforms, they have obviously worked
most of the kinks out of the generalized threading and processes idea (along
with many other useful abstractions).

Even more interesting than generalized threading would be generalized
software transactions. The Intel compiler has an experimental version that
does this:
http://softwarecommunity.intel.com/a...s/eng/1460.htm

As we scale to larger and larger numbers of CPUs, the software transaction
model is the one that gains traction. This document is very illuminating in
that regard:
http://internap.dl.sourceforge.net/s..._submitted.pdf


** Posted from http://www.teranews.com **
Jun 27 '08
126 6788
On 16 avr, 18:21, Ke Jin <kjin...@gmail. comwrote:
On Apr 15, 3:28 pm, "Dann Corbit" <dcor...@connx. comwrote:
Rather than create a new way of doing
things:http://www.open-std.org/jtc1/sc22/wg...008/n2497.html
why not just pick up ACE into the existing
standard:http://www.cse.wustl.edu/~schmidt/ACE.html the same
way that the STL (and subsequently BOOST) have been
subsumed? Since it already runs on zillions of platforms,
they have obviously worked most of the kinks out of the
generalized threading and processes idea (along with many
other useful abstractions).
First, ACE thread is a library based solution. There are many
discussions on why C++0x thread choose a new language based
approach instead (See <http://www.artima.com/forums/flat.jsp?
forum=226&threa d=180936and Boehm's article of "threads
cannot be implemented as a library").
I don't think that that's entirely the problem. There are
different levels of standardizing threads---ACE, like Boost, and
all of the other threading libraries I've seen for C++, seem to
content themselves with just defining a more or less "standard"
interface to whatever the OS offers. They don't address the
language level problems, nor do they attempt to (nor can they,
really).

The standard, obviously, has to, and threading is more than just
a library issue in the standard. But the standard also has to
address the interface: how the user starts a thread,
synchronizes different threads, etc. And that is a library
issue.

IMHO, there is a serious problem at this level. I don't think
that the actual technologies are mature enough. Every new
library which comes out does it differently, and we don't have
enough experience with any of them to really say what is best.
On the other hand, politically, it is a must if C++ is to
survive and prosper. So we'll do the best we can, and hope that
whatever we do won't cause problems down the road, when we have
some real experience under our belts.

(It's worth pointing out that while normally, a standard should
only standardize existing practice, in this case, the "existing
practice" is that most threaded programs have subtle bugs, and
don't work correctly in some special cases.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #11
On Apr 16, 12:28*am, "Dann Corbit" <dcor...@connx. comwrote:
Rather than create a new way of doing things:http://www.open-std.org/jtc1/sc22/wg...008/n2497.html
...
Are there some examples available in this new notation?

Can someone demonstrate here some canonical examples in this new
proposed
notation?

- Producer-consumer problem (bounded buffer)
- Readers and writers problem
- Dining philosophers problem
- Sleeping barber problem
- Santa Claus problem (http://stwww.weizmann.ac.il/g-cs/benari/
articles/santa-claus-problem.pdf)

It would be interesting to see how the proposal works out.

Best Regards,
Szabolcs
Jun 27 '08 #12
On Apr 16, 12:28*am, "Dann Corbit" <dcor...@connx. comwrote:
Rather than create a new way of doing things:http://www.open-std.org/jtc1/sc22/wg...008/n2497.html
...
I like that some higher level construction is also there at last (at
condition_varia ble):

<quote>
template <class Predicate>
void wait(unique_loc k<mutex>& lock, Predicate pred);
Effects:
As if:
while (!pred())
wait(lock);
</quote>

Now programming the get operation of a bounded buffer would look
something like this, I guess:

queue BB::q;
mutex BB::m;
condition_varia ble BB::empty;
condition_varia ble BB::full;
int BB::get()
{
int b;
unique_lock<mut exlock(m);
full.wait(lock, !q.empty());
b = q.get();
empty.notify_on e();
return b;
}

Although there is still some duplication in `full.wait(lock , !
q.empty());', it is much closer to this simple pseudo code (where
`when' is a keyword for a conditional critical region statement) than
a pthread version:

shared queue BB::q;
int BB::get()
{
int b;
when (!q.empty()) {
b = q.get();
}
return b;
}

Best Regards,
Szabolcs
Jun 27 '08 #13
Hi James,

Thanks for providing some additional info.
Or no model; like most other libraries, it's just a wrapper for
whatever the implementation gives you.
That's not entirely the case, e.g., the ACE_Thread_Mana ger is more
than just a wrapper over the underlying implementation. Naturally, if
the OS doesn't support threads at all it's hard for a library-based
implementation to do much about this..
Seriously, what I was referring to was the fact that you have (or
had, at least) a Thread class, from which the user had to derive.
I assume you're referring to ACE_Task here? It implements an Active
Object model that's similar to Java's Thread class + a synchronized
message queue.
This was, of course, the accepted practice when ACE first appeared,
but we've found better solutions since then.
Can you please point to some descriptions of these solutions?
There's also the problem, IIRC, that there is no real distinction
between detached threads and joinable threads.
It's not clear what you mean by this - can you please explain? The
ACE_Thread_Mana ger implements both detached and joinable threads atop
all the underlying operating systems, not just POSIX pthreads.

Thanks,

Doug
--
Dr. Douglas C. Schmidt Professor and Associate Chair
Electrical Engineering and Computer Science TEL: (615) 343-8197
Vanderbilt University WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203 NET: d.*******@vande rbilt.edu
Jun 27 '08 #14
"Chris Thomasson" <cr*****@comcas t.netwrote in message
news:EL******** *************** *******@comcast .com...
"Dann Corbit" <dc*****@connx. comwrote in message
news:52******** **********@news .teranews.com.. .
>Rather than create a new way of doing things:
http://www.open-std.org/jtc1/sc22/wg...008/n2497.html
why not just pick up ACE into the existing standard:
http://www.cse.wustl.edu/~schmidt/ACE.html
the same way that the STL (and subsequently BOOST) have been subsumed?
Since it already runs on zillions of platforms, they have obviously
worked
most of the kinks out of the generalized threading and processes idea
(along
with many other useful abstractions).

Even more interesting than generalized threading would be generalized
software transactions. The Intel compiler has an experimental version
that
does this:
http://softwarecommunity.intel.com/a...s/eng/1460.htm

Check this out:

http://groups.google.com/group/comp....e27f5e0570910d
Here is how to completely live-lock their STM:

http://groups.google.com/group/comp....a8ed18e97130b2
It's no where near ready for prime time. STM has issues with scalability
and live-lock.

>As we scale to larger and larger numbers of CPUs, the software
transaction
model is the one that gains traction. This document is very illuminating
in
that regard:
http://internap.dl.sourceforge.net/s..._submitted.pdf

This is _very_ misleading to say the least. They only talk about live-lock
in terms of transactions getting invalidated by other low-priority
transactions. This is definitely not the only way to live-lock a STM.

Here is just one of many ways:

http://groups.google.com/group/comp....356c832812213b


STM have a whole lot of scaling issues. Here are some of them:

http://groups.google.com/group/comp....ef56a090c052d9
Its no silver-bullet indeed. I would go with distributed message-passing
over STM any day.
I was not aware of the shortfalls of the STM approach, having only read
glowing reviews. Thanks for the pointers. I was going to download and try
the Intel compiler (but was foiled by the Java interface) so I think I will
halt efforts in that direction until things shake out more thoroughly.
** Posted from http://www.teranews.com **
Jun 27 '08 #15
"Szabolcs Ferenczi" <sz************ ***@gmail.comwr ote in message
news:24******** *************** ***********@d1g 2000hsg.googleg roups.com...
On Apr 16, 12:28 am, "Dann Corbit" <dcor...@connx. comwrote:
Rather than create a new way of doing
things:http://www.open-std.org/jtc1/sc22/wg...008/n2497.html
...
I like that some higher level construction is also there at last (at
condition_varia ble):
[...]

Indeed. That's a major plus for me. The really cool thing, for me at least,
is that the next C++ will allow me to create a 100% standard implementation
of my AppCore library <http://appcore.home.co mcast.netwhich currently uses
POSIX Threads and X86 assembly. The fact that C++ has condition variables,
mutexs, atomic operations and fine-grain memory barriers means a lot to me.
Finally, there will be such a thing as 100% portable non-blocking
algorithms. I think that's so neat.

Jun 27 '08 #16
"Dann Corbit" <dc*****@connx. comwrote in message
news:57******** **********@news .teranews.com.. .
"Chris Thomasson" <cr*****@comcas t.netwrote in message
news:EL******** *************** *******@comcast .com...
[...]
>STM have a whole lot of scaling issues. Here are some of them:
[...]
>>
Its no silver-bullet indeed. I would go with distributed message-passing
over STM any day.

I was not aware of the shortfalls of the STM approach, having only read
glowing reviews. Thanks for the pointers.
No problem. Unfortunately, 99% of the STM research papers seem to
continently leave out a list of caveat's. IMHO, STM is a good tool to have
around, but its not the "silver-bullet" that most of the papers hint at. You
can make some good use out of a STM, but you have to be really careful, and
know exactly what your doing inside those atomic-blocks. If you make poor
decisions in those transactional atomic-blocks, your going to get burned by
scaling issues and sporadic periods of live-lock during periods of high, or
even moderate, load on the system.

I was going to download and try the Intel compiler (but was foiled by the
Java interface) so I think I will halt efforts in that direction until
things shake out more thoroughly.
Yeah. I would lurk around their forum and study some of the discussions
going on in there. One post in particular caught my eye:

http://softwarecommunity.intel.com/i.../30248420.aspx
Here is the exact response that Haris Volos got from Jim Cownie who works in
the lab where this experimental development is being conducted:
"What semantics are you expecting from transactions?
If you consider them to have the same semantics as a single global lock,
then this code clearly deadlocks, so it is no big surprise that it can also
deadlock with TM..."
He is telling the truth indeed.

Jun 27 '08 #17
On Apr 16, 6:21*pm, Ke Jin <kjin...@gmail. comwrote:
First, ACE thread is a library based solution. There are many
discussions on why C++0x thread choose a new language based approach
instead
(See <http://www.artima.com/forums/flat.jsp?forum= 226&thread=1809 36>
and Boehm's article of "threads cannot be
implemented as a library").
Is not "Multi-threading Library for Standard C++" just another
library?

I cannot see the language features for concurrency but only the
library ones. For instance, you can instantiate a thread from a
library class. There is no language element for defining a thread, is
there?

There is no keyword in C++0x to mark the shared data. Consequently the
compiler will not be able to check whether the shared data is accessed
properly inside critical region or not.

The low level library means such as mutex and condition variable are
there but there is no higher level language means to define a critical
region or conditional critical region or monitor (see the `shared
class' as it was originally proposed). I mean at the language level
you have nothing new compared to the library level. At least I cannot
see anything like that in the attached "Multi-threading Library for
Standard C++ (Revision 1)"
http://www.open-std.org/jtc1/sc22/wg...thread.threads

Perhaps someone can help me out.

Best Regards,
Szabolcs
Jun 27 '08 #18
On Apr 18, 12:49 am, Szabolcs Ferenczi <szabolcs.feren ...@gmail.com>
wrote:
On Apr 16, 6:21 pm, Ke Jin <kjin...@gmail. comwrote:
First, ACE thread is a library based solution. There are many
discussions on why C++0x thread choose a new language based approach
instead
(See <http://www.artima.com/forums/flat.jsp?forum= 226&thread=1809 36>
and Boehm's article of "threads cannot be
implemented as a library").

Is not "Multi-threading Library for Standard C++" just another
library?
Did you read Bohem's article?
>
I cannot see the language features for concurrency but only the
library ones.
The biggest advancement that C++0x will add to C++ in the are of
threading (other than acknowledge that it exists of course) is the
introduction of a (quite advanced, BTW) memory model, which is a
*pure* language feature.
Also it introduces atomic operations which must be implemented at
the language level.

Everything else is pretty much just standardizing pretty the status
quo.
For instance, you can instantiate a thread from a
library class. There is no language element for defining a thread, is
there?
So what?
>
There is no keyword in C++0x to mark the shared data.
No need for that if you use locks. For small atomic POD objects there
is the atomic<template class which uses the appropriate magic to
make access atomic without locks.
Consequently the
compiler will not be able to check whether the shared data is accessed
properly inside critical region or not.
The memory model prohibits any optimizations (very few actually) that
could
break properly locked (or fenced) code.
The low level library means such as mutex and condition variable are
there but there is no higher level language means to define a critical
region
scoped_lock? Why do you need a language level mean when a library
approach
works just fine and is more in line with the 'C++ Way'
or conditional critical region or monitor (see the `shared
class' as it was originally proposed). I mean at the language level
you have nothing new compared to the library level. At least I cannot
see anything like that in the attached "Multi-threading Library for
Standard C++ (Revision 1)"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html#th.. .

Higher level abstractions can (and will) be built on top of the low
level infrastructure as pure library extensions. The standard
committee mostly
standardizes what already exists and tries to introduce as little
(untested)
innovations as possible.

--
Giovanni P. Deretta
Jun 27 '08 #19
On Apr 17, 9:25 pm, schm...@tango.d re.vanderbilt.e du (Douglas C.
Schmidt) wrote:
Or no model; like most other libraries, it's just a wrapper for
whatever the implementation gives you.
That's not entirely the case, e.g., the ACE_Thread_Mana ger is
more than just a wrapper over the underlying implementation.
Naturally, if the OS doesn't support threads at all it's hard
for a library-based implementation to do much about this..
What I meant is that you don't really define when external
synchronization is needed, and when it isn't. Under Posix,
external synchronization is needed when Posix says it's needed,
and under Windows, when Windows says it's needed.

This is the aspect which really has to be treated at the
language level: what does a "sequence point" mean in a
multithreaded environment? There are also library aspects: when
do I need external synchronization when using library components
in two different threads.
Seriously, what I was referring to was the fact that you
have (or had, at least) a Thread class, from which the user
had to derive.
I assume you're referring to ACE_Task here? It implements an
Active Object model that's similar to Java's Thread class + a
synchronized message queue.
And Java's Thread class is an example of a poorly designed
interface for threading. At least today; it was pretty much
standard practice when it appeared, but we've learned a lot
since then. And are still learning: I'm not sure that even
today, threading technology is mature enough to be technically
ready for standardization . (But politically, we don't have a
choice. If the next version of the C++ standard doesn't address
threading, the language is probably dead.)
This was, of course, the accepted practice when ACE first
appeared, but we've found better solutions since then.
Can you please point to some descriptions of these solutions?
Boost offers parts of them. The whole concept of functional
objects changes the situation considerably.

IMHO, too, what I've learned from practical experience is that
joinable threads and detached threads are two very different
beasts. For detached threads, the best solution I've found so
far is a template function, something more or less like:

template< typedef Function >
void
startDetachedTh read(
Function f )
{
boost::thread( f ) ;
}

Fire and forget, in sum, with copy semantics handling all of the
memory management issues.

For joinable threads, you still want the thread class to take
the functional object as an argument (so that you're ensured
that it fully constructed before the thread starts). In Java,
for example, deriving from java.lang.Threa d is a common source
of errors (which don't occur if you pass a Runnable to the
constructor of Thread). In C++, the issue is further
complicated by memory management issues, since there's no
garbage collection. (I don't think that they're necessarily
difficult issues, and I suspect that there are several
acceptable solutions. But they do have to be addressed.)

I'm not really too sure how ACE handles this; it's been a long
time since I last looked at it (and it may have evolved since
then).

I'm also not too sure how (or if) ACE handles propagation of an
exception accross a join. It's important that the standard
offer some sort of support for this as well. Although I don't
think it should be the default, and it doesn't bother me if it
requires some programming effort to get, it is currently
impossible to implement in Boost, and I suspect in any other
threading system (since it also requires some language support,
which isn't there at present).
There's also the problem, IIRC, that there is no real
distinction between detached threads and joinable threads.
It's not clear what you mean by this - can you please explain?
The ACE_Thread_Mana ger implements both detached and joinable
threads atop all the underlying operating systems, not just
POSIX pthreads.
But do you even need a thread manager for detachable threads.

Note that I'm talking here about the lowest level; the one which
must be in the standard. There's definitely place for more
elaborate (and less general) models at a higher level.

With regards to standardization , what ACE has going for it, of
course, is the fact that it probably has more users than all
other systems combined, and we have a lot of concrete experience
with it. What it has going against it is its age (it doesn't
take into account all of the changes in programming style in the
last years), and the fact that no one in the committee is
championing it. (The Boost group are very active in
standardization . You and others working on ACE don't seem to be
so.)

What all existing libraries have going against them (IMHO) is
that the "existing practice" with regards to threads is that
most multi-threaded programs don't actually work, or won't if
the active thread changes at the wrong moment, of if they're
ported to a multi-processor system, or if any one of a number of
other things occur. From a technical point of view, this means
that it's probably too early to standardize threading this go
round. From a political point of view, however, I don't think
we have a choice.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
6607
by: Jorge Godoy | last post by:
Hi! I must have been searching in the wrong places or with the wrong keywords but I couldn't find out how to implement something such as what is done by the threading module on Windows (95, 98 and XP are the ones used by my clients). My preference is for something available in the standard library if possible. I have a simple task where I want my GUI to be able to open several
17
2455
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next = gen.next() finally:
4
4930
by: Joe Wong | last post by:
Hi, Is there any way to increase/decrease a thread priority in Python? Best regards, -- Wong
77
5402
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
5
1973
by: Roshan | last post by:
This is regarding the article titled "C++ & Double-Checked Locking" by Scott Meyers and Andrei in DDJ July 2004 issue. I think the reasoning in this article is fundamentally flawed due the authors mixing up a couple of concepts (observable behavior & side effects) that are defined separately in the standard. Background: In the following statement... class Singelton {
4
1268
by: Lionel van den Berg | last post by:
Hi all, I'm just wondering what's the best option for threading in C++? I've used pthreads and forking in C (the latter is not appropriate for my situation now). All I want to do is run a function in a new thread, it's a simple task, no interaction with other threads etc. so I don't have to worry about deadlock, starvation and so on. Thanks,
2
3275
by: Juuso Hukkanen | last post by:
I need a list of multithreading unsafe C (C99) functions/features. comp.programming.threads provided an initial list of C:ish functions, with following ANSI C functions: asctime, gmtime, localtime, ctime, tmpnam, strtok http://www.lambdacs.com/cpt/FAQ.html#Q150 However, extra Googling hinted rand() and srand(), also being unsuitable for multi-threading - opinions? And what is the status of
9
1870
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this CPU-intensive work in another thread, but of course this won't work because of Python's GIL. There's a lot of past discussion on this, and I want to bring it up again because with the work on Python 3000, I think it is worth trying
1
4403
by: Seun Osewa | last post by:
Hello, I've tried to run several threading examples in Python 2.5.1 (with Stackless) For example: import threading theVar = 1 class MyThread ( threading.Thread ):
0
9994
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9842
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11265
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10859
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8036
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7191
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5882
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4712
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.