C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Run functions concurrently

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Frederick Gotham
Guest





PostPosted: Sat Oct 21, 2006 9:10 am    Post subject: Run functions concurrently Reply with quote



The Standard says that the behaviour is unspecified with regard to the
order of evaluation in the following:

int FuncA();
int FuncB();

int main()
{
FuncA() + FuncB();
}

FuncA might be called first, or then again it might be FuncB. Does the
Standard place any restriction on the two of them running at the same time
(e.g. if there are two CPU's or whatever)?

Is the behaviour of the following snippet undefined because of a sequence
point violation? (Again, I'm unsure as to whether the implementation may
run them concurrently.)

int i = 5;

int FuncA() { return ++i; }

int FuncB() { return ++i; }

int main()
{
FuncA() + FuncB();
}

If there were a requirement that either FuncA or FuncB must be executed on
its own prior to invocation of the second function, then it would seem that
there would be no problem -- a problem would only arise if they were
executed concurrently. Here's a more sensible example:

char str[] = "My dog is XX years old."

int FuncA()
{
str[10] = ' ';
str[11] = '8';

SomeLibraryFunction(str);

return 0;
}

int FuncB()
{
str[10] = '1';
str[11] = '1';

SomeLibraryFunction(str);

return 0;
}

int main()
{
FuncA() + FuncB();
}

If the two functions were to be executed one after the other, then there
would be no problem. If they were to be executed concurrently, however,
then the string might get mangled... one of them might produce "18" instead
of " 8" or "11".

Which leads me onto one more thing...

Let's say we have two functions, AnalyseStrata and TriangulateSignals.
Let's say that they're invoked as follows:

int main()
{
AnalyseStrata();
TriangulateSignals();
}

Obviously, because of sequence points, the former function must complete
execution prior to invocation of the latter function.

Let's say that the former function, on a particular system, takes 3 minutes
to execute, and that the latter function takes 7 minutes to execute. Let's
say though, that the system in question has two CPU's, and that the
functions in question can be run concurrently. Should the language provide
a way of exploiting this? One method I can think of might be something
like:

(AnalyseStrata(),0) + (TriangulateSignals(),0);

--

Frederick Gotham
Back to top
Tomekstasiowski@buziaczek
Guest





PostPosted: Sat Oct 21, 2006 9:10 am    Post subject: Re: Run functions concurrently Reply with quote



http://s9.bitefight.pl/c.php?uid=91452
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.