concurrency - c++ future call local variable -


when using c++ future call function, if define 2 future objects a,b , call same function foo

 = async(launch::async,foo);  b = async(launch::async,foo); 

is same running function twice?

foo() foo() 

i.e. a , b each running private copy of foo?

they use same function example shows.

void foo() {     static int counter=0;     cout<<counter++<<endl;     return; }  int main() {   std::future<void> resulta(async(launch::async,foo));   resulta.get();    std::future<void> resultb(async(launch::async,foo));   resultb.get();    return 0; } 

output:

0

1

this shows same static counter variable used bcz output not 0,0 0,1 (incremented goes foo)

hope helps,


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -