473,898 Members | 4,678 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 6786

"Markus Elfring" <Ma************ @web.dewrote in message
news:68******** *****@mid.indiv idual.net...
Szabolcs Ferenczi schrieb:
>Finally, let me stress that I am not suggesting that you would make
either Concurrent Pascal, Edison, Ada or OCCAM out of C++. These are
just examples containing useful ideas with respect to concurrent
programming language features.

Do you like the approach "C++CSP2"?
http://www.cs.kent.ac.uk/projects/ofa/c++csp/

Whats this ... Occam in C++?

Actually seems sane... I like it !

regards
Andy Little
Jun 27 '08 #101
On May 3, 10:38 am, "kwikius" <a...@servocomm .freeserve.co.u kwrote:
"Markus Elfring" <Markus.Elfr... @web.dewrote in message

news:68******** *****@mid.indiv idual.net...
Szabolcs Ferenczi schrieb:
Finally, let me stress that I am not suggesting that you would make
either Concurrent Pascal, Edison, Ada or OCCAM out of C++. These are
just examples containing useful ideas with respect to concurrent
programming language features.
Do you like the approach "C++CSP2"?
http://www.cs.kent.ac.uk/projects/ofa/c++csp/

Whats this ... Occam in C++?

Actually seems sane... I like it !

regards
Andy Little
However, this is clearly not a shared memory approach. It may well
make lots of sense, but it's not what we set out to standardize. It's
also not what most applications tend to use. Or what that cache
coherence hardware in your PC was designed for. Some of the other
approaches discussed in this thread also seem to border on distributed
memory approaches, and similar comments may apply.

Hans

Jun 27 '08 #102
On May 4, 1:59*am, "Boehm, Hans" <hans.bo...@hp. comwrote:
On May 3, 10:38 am, "kwikius" <a...@servocomm .freeserve.co.u kwrote:
"Markus Elfring" <Markus.Elfr... @web.dewrote in message
news:68******** *****@mid.indiv idual.net...
Szabolcs Ferenczi schrieb:
>Finally, let me stress that I am not suggesting that you would make
>either Concurrent Pascal, Edison, Ada or OCCAM out of C++. These are
>just examples containing useful ideas with respect to concurrent
>programming language features.
Do you like the approach "C++CSP2"?
>http://www.cs.kent.ac.uk/projects/ofa/c++csp/
Whats this ... Occam in C++?
Actually seems sane... I like it !
regards
Andy Little

However, this is clearly not a shared memory approach. *It may well
make lots of sense, but it's not what we set out to standardize. *It's
also not what most applications tend to use. *Or what that cache
coherence hardware in your PC was designed for. *Some of the other
approaches discussed in this thread also seem to border on distributed
memory approaches, and similar comments may apply.

Hans
Jun 27 '08 #103

"Boehm, Hans" <ha********@hp. comwrote in message
news:13******** *************** ***********@f24 g2000prh.google groups.com...
On May 3, 10:38 am, "kwikius" <a...@servocomm .freeserve.co.u kwrote:
>"Markus Elfring" <Markus.Elfr... @web.dewrote in message

news:68******* ******@mid.indi vidual.net...
Szabolcs Ferenczi schrieb:
Finally, let me stress that I am not suggesting that you would make
either Concurrent Pascal, Edison, Ada or OCCAM out of C++. These are
just examples containing useful ideas with respect to concurrent
programming language features.
Do you like the approach "C++CSP2"?
http://www.cs.kent.ac.uk/projects/ofa/c++csp/

Whats this ... Occam in C++?

Actually seems sane... I like it !

regards
Andy Little

However, this is clearly not a shared memory approach. It may well
make lots of sense, but it's not what we set out to standardize. It's
also not what most applications tend to use. Or what that cache
coherence hardware in your PC was designed for. Some of the other
approaches discussed in this thread also seem to border on distributed
memory approaches, and similar comments may apply.
Please don't attach any weight to my comments about concurrency. I don't use
threads except in tiny test apps just to experiment.

My understanding of the status quo re concurrency in C++0x is that you are
concentrating on low level primitives and obviously the major concern is
whether you have got those right to build higher level constructs.

FWIW Here are 2 areas where I can see that concurrency would be useful for
me.

The first is in file output. When the user presses "save" I create a process
to perform the job. Its a lot easier Not to create a process and just show a
wait cursor, though not ideal for the user. OTOH If I create a separate
process I need to figure out some strategy for what happens if something
goes wrong, and how I get that reported back at some unknown time.

The other area is in processing vectors(math vectors of compile time fixed
size rather than std::vector). Theoretically multiplication of a vector by a
scalar or dot product could be done in parallel, and ideally expressible
somehow in the language I think rather than requiring assembler.

The following is some quick attempt at a language extension to express sum
and dot on a vector FWIW:

regards
Andy Little

// vector sum

// even size vector add every element to next recursively
template <int Size>
{where Size % 2 == 0 }
double
sum(Vect<Sizev)
{
static const int N = Size/2;
vect<Nin;
// some notation to say do these calcs in parallel
parallel[N]:n{
in[n] = v[2*n] + v[2*n+1];
}
// recurse until size of vector is 1
return sum(in);
}

// odd size vector
template <int Size>
{where ( Size % 2 ==1 ) && ( Size 1 ) }
double
sum(Vect<Sizev)
{
return v[0] + sum(vect_view<1 ,Size>(v));
}

// size 1 vector
template <int Size>
double
{where Size ==1 }
sum(Vect<Sizev)
{
return v[0];
}

//vector dot
template <int Size>
dot_product( vect<SizevL, vect<Sizevr )
{
vect<Sizein;
// do mux in parallel
parallel[Size]:n {
in[n] = vl[n] * Vr[n];
}
return sum(in);
}
Jun 27 '08 #104
On May 4, 1:59*am, "Boehm, Hans" <hans.bo...@hp. comwrote:
On May 3, 10:38 am, "kwikius" <a...@servocomm .freeserve.co.u kwrote:
"Markus Elfring" <Markus.Elfr... @web.dewrote in message
news:68******** *****@mid.indiv idual.net...
Szabolcs Ferenczi schrieb:
>Finally, let me stress that I am not suggesting that you would make
>either Concurrent Pascal, Edison, Ada or OCCAM out of C++. These are
>just examples containing useful ideas with respect to concurrent
>programming language features.
Do you like the approach "C++CSP2"?
>http://www.cs.kent.ac.uk/projects/ofa/c++csp/
Whats this ... Occam in C++?
Actually seems sane... I like it !
Pleas ignore the previous post, just pushed the button by accident.
However, this is clearly not a shared memory approach.
That is right. They clearly missed the point here. It frequently
happens when people are not disciplined enough.

What I was discussing in the original post where they picked up a
keyword was the following: I think that at the language level most
probably an adapted form of Dijkstra's Guarded Commands could be used
to cope with non-determinism.

I have just given some examples that Guarded Commands has been adapted
in some languages and language proposals already:

1) for shared memory communication in the language proposal
Distributed Processes (DP) or in the Edison language; and

2) for message-based communication in the Communicating Sequential
Processes (CSP) of which a language realisation is the OCCAM language.

The lad just picked up a keyword. It is not the first time it happens.
Though, I clearly indicated that the mention of these keywords is just
illustration and this text is even copied here.
>*It may well
make lots of sense, but it's not what we set out to standardize. *It's
also not what most applications tend to use.
For standardisation , probably it is out of question. However, if you
consider the needs of a modern concurrent programming language, it
should probably deal with mixed architectures as well, i.e. mixed
shared memory and distributed memory ones. The Guarded commands can be
adapted to both architectures since the main issue there is that the
language level construction matches with the non-determinism that
arises in any co-operating process architecture.

I guess that mixed architectures are far away from the low level
library-based standardisation efforts in C++0x, however. Lads might
pick up keywords again, though.

Best Regards,
Szabolcs
Jun 27 '08 #105
On 2008-05-04 11:07, kwikius wrote:
The other area is in processing vectors(math vectors of compile time fixed
size rather than std::vector). Theoretically multiplication of a vector by a
scalar or dot product could be done in parallel, and ideally expressible
somehow in the language I think rather than requiring assembler.
You might want to check out OpenMP, it makes it very easy to parallelise
things like for-loops. The hard part if finding what to parallelise,
i.e. the loop in the dot-product or the calculation of the dot-product
for a lot of vectors.

--
Erik Wikström
Jun 27 '08 #106

"kwikius" <an**@servocomm .freeserve.co.u kwrote in message
news:48******** **@mk-nntp-2.news.uk.tisca li.com...

<...>
The following is some quick attempt at a language extension to express sum
and dot on a vector FWIW:
<snip pseudo stuff>

Below is a version which is standard C++... no parallel, N in app can be
easily modified for diff size arrays.

Its interesting to see how the asm changes as N gets bigger:

Asm produced by VC8 with optimisation at end, shows how near it is to being
able to parallelise.

regards
Andy Little

//sfinae

template <bool C, typename T = void>

struct where_{

typedef T type;

};

template <typename T>

struct where_<false,T> {};

// fixed size vect

template <int N>

struct vect

{

double elements[N];

vect(double (& ar)[N]){

for (int i = 0; i < N; ++i){

elements[i] = ar[i];

}

}

vect(){}

static const int size = N;

double const & operator [] (int n) const

{

return elements[n];

}

double & operator [] (int n)

{

return elements[n];

}

vect & operator = (vect const & in)

{

for ( int i = 0; i < N ; ++i){

elements[i] = in[i];

}

}

};

template <typename Vect,int Offset>

struct vect_view{

Vect const & v;

vect_view(Vect const & in) : v(in){}

double const & operator [] (int n)const

{

return v[n + Offset];

}

static const int size = Vect::size - Offset;

vect_view & operator = (vect_view const & in)

{

for (int i = 0; i < N ; ++i){

elements[i] = in[i];

}

}

};

template <int N, typename Where = void>

struct sum_impl;

template <int N>

struct sum_impl<N, typename where_<(N >= 2) && ((N %2) ==0) >::type >

{

template <typename T>

double operator()(T const & in)const

{

vect<N/2out;

for (int i = 0; i < N /2 ; ++i){

out[i] = in[i*2] + in[i*2 +1];

}

sum_impl<N/2s;

return s(out);

}

};

template <int N>

struct sum_impl<N, typename where_<(N 2) && ((N %2) == 1)>::type>

{

template <typename T>

double operator()(T const & in)const

{

sum_impl<N-1s;

return in[0] + s(vect_view<T,1 >(in) );

}

};

template <int N>

struct sum_impl<N, typename where_<(N ==1)>::type>

{

template <typename T>

double operator()(T const & in)const

{

return in[0];

}

};

template <typename V>

double sum( V const & v)

{

sum_impl<V::siz es;

return s(v);

}

template <typename V>

double dot( V const & lhs, V const & rhs)

{

vect<V::sizev;

for (int i = 0; i < V::size;++i){

v[i] = lhs[i] * rhs[i];

}

return sum(v);

}

///-----------------------------

#include <iostream>

int main()

{

static const int n = 4;

double ar[n] ;

std::cout << "input " << n << " doubles\n";

for ( int i = 0; i < n; ++i){

std::cin >ar[i];

}

std::cout << "thankyou\n ";

vect<nvv(ar);

double r = dot(vv,vv);

std::cout << r <<'\n';

}

// asm for n = 4 in VC8

; 136 : double r = dot(vv,vv);

fld QWORD PTR _ar$[esp+72]

fmul ST(0), ST(0)

; 137 : std::cout << r <<'\n';

mov ecx, DWORD PTR
__imp_?cout@std @@3V?$basic_ost ream@DU?$char_t raits@D@std@@@1 @A

fld QWORD PTR _ar$[esp+80]

fmul ST(0), ST(0)

fld QWORD PTR _ar$[esp+88]

fmul ST(0), ST(0)

fld QWORD PTR _ar$[esp+96]

fmul ST(0), ST(0)

fxch ST(2)

faddp ST(3), ST(0)

faddp ST(1), ST(0)

faddp ST(1), ST(0)

fstp QWORD PTR [esp]

call DWORD PTR
__imp_??6?$basi c_ostream@DU?$c har_traits@D@st d@@@std@@QAEAAV 01@N@Z
Jun 27 '08 #107

"Erik Wikström" <Er***********@ telia.comwrote in message
news:UP******** *********@newsb .telia.net...
On 2008-05-04 11:07, kwikius wrote:
>The other area is in processing vectors(math vectors of compile time
fixed
size rather than std::vector). Theoretically multiplication of a vector
by a
scalar or dot product could be done in parallel, and ideally expressible
somehow in the language I think rather than requiring assembler.

You might want to check out OpenMP, it makes it very easy to parallelise
things like for-loops.
....
The hard part if finding what to parallelise,
i.e. the loop in the dot-product or the calculation of the dot-product
for a lot of vectors.
Both .... :-)

regards
Andy Little
Jun 27 '08 #108
On May 3, 10:57 am, "Dmitriy V'jukov" <dvyu...@gmail. comwrote:
and I document that link-time optimization level should be turned down, or
off... Oh well.

Link-time optimization can increase performance by 10-20%. And it's on
by default in release build of MSVC...

Btw, Joe Seigh in atomic-ptr uses following:
#define fence() __asm__ __volatile__ ("" : : : "memory")
#define smrnull(hptr) \
do { \
fence(); \
atomic_store(&h ptr[0], 0); \
atomic_store(&h ptr[1], 0); \
} while (0)
What do you think?
From linux kernel (include/linux/compiler-gcc.h):

/* Optimization barrier */
/* The "volatile" is due to gcc bugs */
#define barrier() __asm__ __volatile__("" : : :"memory")

This thing is prevalent for suppressing compiler optimizations.. .

Dmitriy V'jukov
Jun 27 '08 #109
"Dmitriy V'jukov" <dv*****@gmail. comwrote in message
news:08******** *************** ***********@i36 g2000prf.google groups.com...
On May 3, 10:57 am, "Dmitriy V'jukov" <dvyu...@gmail. comwrote:
and I document that link-time optimization level should be turned down,
or
off... Oh well.

Link-time optimization can increase performance by 10-20%. And it's on
by default in release build of MSVC...

Btw, Joe Seigh in atomic-ptr uses following:
#define fence() __asm__ __volatile__ ("" : : : "memory")
#define smrnull(hptr) \
do { \
fence(); \
atomic_store(&h ptr[0], 0); \
atomic_store(&h ptr[1], 0); \
} while (0)
What do you think?

From linux kernel (include/linux/compiler-gcc.h):

/* Optimization barrier */
/* The "volatile" is due to gcc bugs */
#define barrier() __asm__ __volatile__("" : : :"memory")

This thing is prevalent for suppressing compiler optimizations.. .
Right. I use that when the build detects that its compiling under something
that is compatible with GNU C; _ReadWriteBarri er() on VC++, and external
function call for everything else.

Jun 27 '08 #110

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
4929
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
9993
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
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...
1
10954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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...
0
6078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4297
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3308
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.