public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* std::async from C++11 does not work
@ 2016-03-16  0:00 Ilya Razenshteyn
  2016-03-16  3:00 ` Yaakov Selkowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Ilya Razenshteyn @ 2016-03-16  0:00 UTC (permalink / raw)
  To: cygwin

Hi all,

I'm trying to compile and run the below code. As a result, only one copy 
of "f" is being executed at a time, that is, no new threads are spawned. 
Does anyone know what's going on?

cygwin 2.4.1, gcc 5.3.0, compilation options are "g++ test.cpp -o test 
-O3 -Wall -std=c++11 -lpthread".


Ilya

#include <future>
#include <iostream>

using namespace std;

void f(int id) {
   for (int i = 0; i < 100000; ++i) {
     cout << id << endl;
   }
}

int main() {
   std::async(std::launch::async, &f, 1);
   std::async(std::launch::async, &f, 2);
   return 0;
}

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: std::async from C++11 does not work
  2016-03-16  0:00 std::async from C++11 does not work Ilya Razenshteyn
@ 2016-03-16  3:00 ` Yaakov Selkowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Yaakov Selkowitz @ 2016-03-16  3:00 UTC (permalink / raw)
  To: cygwin

On 2016-03-15 19:00, Ilya Razenshteyn wrote:
> I'm trying to compile and run the below code. As a result, only one copy
> of "f" is being executed at a time, that is, no new threads are spawned.
> Does anyone know what's going on?

Could be your code.  I tried other code[1] using std::async, and 
multiple cores are definitely used when std::launch::async is specified.

[1] https://github.com/sol-prog/async_tutorial

-- 
Yaakov

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-16  3:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-16  0:00 std::async from C++11 does not work Ilya Razenshteyn
2016-03-16  3:00 ` Yaakov Selkowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).