C++11 thread support in MinGW?

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

C++11 thread support in MinGW?

Andrew Pennebaker
When will MinGW get things like std::async? When I try to include futures, g++ reports:

error: declaration of 'struct std::future<void>'

--
Cheers,

Andrew Pennebaker

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

niXman
2013/3/20 Andrew Pennebaker:
> When will MinGW get things like std::async? When I try to include futures,
> g++ reports:
>
> error: declaration of 'struct std::future<void>'

Hi,

Please show your sample code.


--
Regards,
niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingwbuilds/
___________________________________________________
Another online IDE: http://liveworkspace.org/

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

Yongwei Wu
In reply to this post by Andrew Pennebaker
GCC 4.7 does not support futures. GCC 4.8 will.

On 20 March 2013 20:17, Andrew Pennebaker <[hidden email]> wrote:

> When will MinGW get things like std::async? When I try to include futures,
> g++ reports:
>
> error: declaration of 'struct std::future<void>'
>
> --
> Cheers,
>
> Andrew Pennebaker
> www.yellosoft.us
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_mar
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> This list observes the Etiquette found at
> http://www.mingw.org/Mailing_Lists.
> We ask that you be polite and do the same.  Disregard for the list etiquette
> may cause your account to be moderated.
>
> _______________________________________________
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users
> Also: mailto:[hidden email]?subject=unsubscribe



--
Wu Yongwei
URL: http://wyw.dcweb.cn/

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

niXman
2013/3/22 Yongwei Wu:
> GCC 4.7 does not support futures. GCC 4.8 will.

You are mistaken ;)
http://liveworkspace.org/code/3OCLX0$0


--
Regards,
niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingwbuilds/
___________________________________________________
Another online IDE: http://liveworkspace.org/

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

niXman
2013/3/22 niXman:
> 2013/3/22 Yongwei Wu:
>> GCC 4.7 does not support futures. GCC 4.8 will.
>
> You are mistaken ;)
> http://liveworkspace.org/code/3OCLX0$0

This code also work as expected if MinGW-builds[1] used.


[1] http://sourceforge.net/projects/mingwbuilds/


--
Regards,
niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingwbuilds/
___________________________________________________
Another online IDE: http://liveworkspace.org/

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

Yongwei Wu
In reply to this post by niXman
On 22 March 2013 22:16, niXman <[hidden email]> wrote:
> 2013/3/22 Yongwei Wu:
>> GCC 4.7 does not support futures. GCC 4.8 will.
>
> You are mistaken ;)
> http://liveworkspace.org/code/3OCLX0$0

Oops, memory got corrupt. In fact, I successfully compiled a future
test under Linux GCC 4.6 (I am repeating it now; I am not sure whether
I tested on 4.7), but I considered it a failure and forgot about it,
since the async part did not execute in parallel! And the header file
is missing on Windows, probably because the runtime support is even
more incomplete. Then I mixed things together.

Sorry for the inaccurate information.

--
Wu Yongwei
URL: http://wyw.dcweb.cn/

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

K. Frank
Hi Yongwei!

On Fri, Mar 22, 2013 at 11:18 AM, Yongwei Wu <[hidden email]> wrote:

> On 22 March 2013 22:16, niXman <[hidden email]> wrote:
>> 2013/3/22 Yongwei Wu:
>>> GCC 4.7 does not support futures. GCC 4.8 will.
>>
>> You are mistaken ;)
>> http://liveworkspace.org/code/3OCLX0$0
>
> Oops, memory got corrupt. In fact, I successfully compiled a future
> test under Linux GCC 4.6 (I am repeating it now; I am not sure whether
> I tested on 4.7), but I considered it a failure and forgot about it,
> since the async part did not execute in parallel! And the header file
> is missing on Windows, probably because the runtime support is even
> more incomplete. Then I mixed things together.

One more data point:  Futures worked for me as far back as 4.5.2 using
a mingw-w64 build with which I used the pthreads-w64 that came with
it to activate std::thread support.  I was able to pass both values and
exceptions back through the future.

> ...
> Wu Yongwei

Happy Future Hacking!


K. Frank

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

Yongwei Wu
On 22 March 2013 23:29, K. Frank <[hidden email]> wrote:

> Hi Yongwei!
>
> On Fri, Mar 22, 2013 at 11:18 AM, Yongwei Wu <[hidden email]> wrote:
>> On 22 March 2013 22:16, niXman <[hidden email]> wrote:
>>> 2013/3/22 Yongwei Wu:
>>>> GCC 4.7 does not support futures. GCC 4.8 will.
>>>
>>> You are mistaken ;)
>>> http://liveworkspace.org/code/3OCLX0$0
>>
>> Oops, memory got corrupt. In fact, I successfully compiled a future
>> test under Linux GCC 4.6 (I am repeating it now; I am not sure whether
>> I tested on 4.7), but I considered it a failure and forgot about it,
>> since the async part did not execute in parallel! And the header file
>> is missing on Windows, probably because the runtime support is even
>> more incomplete. Then I mixed things together.
>
> One more data point:  Futures worked for me as far back as 4.5.2 using
> a mingw-w64 build with which I used the pthreads-w64 that came with
> it to activate std::thread support.  I was able to pass both values and
> exceptions back through the future.

Good to know. Does it work completely? Can you try a test?

--- begin test_future.cpp ---
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

#include <future>
#include <iostream>

#ifdef _WIN32
void sleep(int sec)
{
        Sleep(sec * 1000);
}
#endif

int find_the_answer_to_ltuae()
{
        std::cout << "Finding answers ..." << std::endl;
        sleep(2);
        return 42;
}

void do_other_stuff()
{
        std::cout << "Other stuff starts" << std::endl;
        sleep(1);
        std::cout << "Other stuff done" << std::endl;
}

int main()
{
        std::future<int> the_answer = std::async(find_the_answer_to_ltuae);
        do_other_stuff();
        std::cout << "The answer is " << the_answer.get() << std::endl;
}
--- end test_future.cpp ---

Though it passed compilation on Ubuntu 12.04 (GCC 4.6.3), the total
running time of the program is 3 seconds, instead of the expected 2.

Currently clang/libc++ (on Mac) and MSVC 2012 (on Windows) give me the
expected results.

--
Wu Yongwei
URL: http://wyw.dcweb.cn/

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

K. Frank
Hello Yongwei!

On Fri, Mar 22, 2013 at 11:40 AM, Yongwei Wu <[hidden email]> wrote:

> On 22 March 2013 23:29, K. Frank <[hidden email]> wrote:
>> Hi Yongwei!
>> On Fri, Mar 22, 2013 at 11:18 AM, Yongwei Wu <[hidden email]> wrote:
>> ...
>> One more data point:  Futures worked for me as far back as 4.5.2 using
>> a mingw-w64 build with which I used the pthreads-w64 that came with
>> it to activate std::thread support.  I was able to pass both values and
>> exceptions back through the future.
>
> Good to know. Does it work completely? Can you try a test?
>
> --- begin test_future.cpp ---
> ...
> int main()
> {
>         std::future<int> the_answer = std::async(find_the_answer_to_ltuae);
>         do_other_stuff();
>         std::cout << "The answer is " << the_answer.get() << std::endl;
> }
> --- end test_future.cpp ---
>
> Though it passed compilation on Ubuntu 12.04 (GCC 4.6.3), the total
> running time of the program is 3 seconds, instead of the expected 2.

I saw an issue similar to yours when I ran my own tests.  From the
notes I took at the time:

   The program runs correctly.  However, the async code appears to
   run synchronously, in that the code passed off to async does not
   run in a separate thread.  Rather, it runs at the time std::future.get()
   is called (not at the time the async is spawned).

   Note, future defines:

      enum class launch { any, async, sync };

   It appears that the default is to use launch::any, but it's not clear
   to me what launch::any does.  Let me try specifying launch::async
   explicitly.

   Okay, that works.  The code passed to async runs asynchronously,
   and task manager shows two additional threads (one for each async
   call) being spawned.

   As expected, one call to async returns normally, and the second throws
   an exception.  This exception in rethrown correctly in the main thread
   when the main thread calls std::future.get().

I would imagine that running synchronously when spawning an async
with the default "launch::any" would count as a bug, but I haven't looked
in detail at what the standard says.

If you spawn your async explicitly with the "launch::async" option, does
that fix your issue?  If so, we're probably seeing the same thing.

Again, this was on a 4.5.2 64-bit mingw-w64 build.  On 32-bit mingw,
I couldn't get std::thread to work on a 4.5.0 mingw build, but I didn't
investigate in detail.  I did get std::thread working (and ran the future
test) on a 4.6 mingw build.

> ...
> Wu Yongwei

Of course, 4.5.2 is kind of old now.  As they say ...

Back to the Future!


K. Frank

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

Dongsheng Song
In reply to this post by Yongwei Wu
On Fri, Mar 22, 2013 at 11:40 PM, Yongwei Wu <[hidden email]> wrote:

> Good to know. Does it work completely? Can you try a test?
>
> --- begin test_future.cpp ---
> #ifdef _WIN32
> #include <windows.h>
> #else
> #include <unistd.h>
> #endif
>
> #include <future>
> #include <iostream>
>
> #ifdef _WIN32
> void sleep(int sec)
> {
>         Sleep(sec * 1000);
> }
> #endif
>
> int find_the_answer_to_ltuae()
> {
>         std::cout << "Finding answers ..." << std::endl;
>         sleep(2);
>         return 42;
> }
>
> void do_other_stuff()
> {
>         std::cout << "Other stuff starts" << std::endl;
>         sleep(1);
>         std::cout << "Other stuff done" << std::endl;
> }
>
> int main()
> {
>         std::future<int> the_answer = std::async(find_the_answer_to_ltuae);
>         do_other_stuff();
>         std::cout << "The answer is " << the_answer.get() << std::endl;
> }
> --- end test_future.cpp ---
>
> Though it passed compilation on Ubuntu 12.04 (GCC 4.6.3), the total
> running time of the program is 3 seconds, instead of the expected 2.
>
> Currently clang/libc++ (on Mac) and MSVC 2012 (on Windows) give me the
> expected results.
>

On Debian Linux (amd64) 7.0, I got system_error:

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian
4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc
--with-arch-32=i586 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)

$ g++ -std=c++11 -O2 test_future.cpp

$ time ./a.out
Other stuff starts
Other stuff done
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error 18446744073709551615
Aborted

real    0m1.005s
user    0m0.000s
sys     0m0.004s

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

Roumen Petrov-3
Dongsheng Song wrote:
> On Debian Linux (amd64) 7.0, I got system_error:
>> [SNIP]
>> Thread model: posix
>> gcc version 4.7.2 (Debian 4.7.2-5)
>>
>> $ g++ -std=c++11 -O2 test_future.cpp
-pthread flag ?
>>
>> $ time ./a.out
>> Other stuff starts
>> Other stuff done
>> terminate called after throwing an instance of 'std::system_error'
>>    what():  Unknown error 18446744073709551615
>> Aborted
>>
Roumen

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

Yongwei Wu
In reply to this post by K. Frank
On 23 March 2013 00:03, K. Frank <[hidden email]> wrote:

>    The program runs correctly.  However, the async code appears to
>    run synchronously, in that the code passed off to async does not
>    run in a separate thread.  Rather, it runs at the time std::future.get()
>    is called (not at the time the async is spawned).
>
>    Note, future defines:
>
>       enum class launch { any, async, sync };
>
>    It appears that the default is to use launch::any, but it's not clear
>    to me what launch::any does.  Let me try specifying launch::async
>    explicitly.
>
>    Okay, that works.  The code passed to async runs asynchronously,
>    and task manager shows two additional threads (one for each async
>    call) being spawned.
>
>    As expected, one call to async returns normally, and the second throws
>    an exception.  This exception in rethrown correctly in the main thread
>    when the main thread calls std::future.get().
>
> I would imagine that running synchronously when spawning an async
> with the default "launch::any" would count as a bug, but I haven't looked
> in detail at what the standard says.
>
> If you spawn your async explicitly with the "launch::async" option, does
> that fix your issue?  If so, we're probably seeing the same thing.

Ha, it works on Linux now. Great thanks! I did not notice the launch
parameter.

This is what I found in N3337:

  if policy & launch::deferred is non-zero — Stores DECAY_COPY
  (std::forward<F>(f)) and DECAY_COPY (std::forward<Args>(args))... in
  the shared state. These copies of f and args constitute a deferred
  function.... The first call to a non-timed waiting function (30.6.4)
  on an asynchronous return object referring to this shared state
  shall invoke the deferred function in the thread that called the
  waiting function. Once evaluation of INVOKE (g, xyz) begins, the
  function is no longer considered deferred. [ Note: If this policy is
  specified together with other policies, such as when using a policy
  value of launch::async | launch::deferred, implementations should
  defer invocation or the selection of the policy when no more
  concurrency can be effectively exploited. — end note ]

I assume launch::any equals to launch::async | launch::deferred, and
launch::sync is the old name of launch::deferred. It seems the C++11
standard allows the GCC behaviour under a condition ("when no more
concurrency can be effectively exploited"). Probably GCC 4.8 will
improve on this.

--
Wu Yongwei
URL: http://wyw.dcweb.cn/

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: C++11 thread support in MinGW?

K. Frank
Hello Yongwei!

Thanks for following up on this.

On Fri, Mar 22, 2013 at 11:40 PM, Yongwei Wu <[hidden email]> wrote:

> On 23 March 2013 00:03, K. Frank <[hidden email]> wrote:
>>    The program runs correctly.  However, the async code appears to
>>    run synchronously, in that the code passed off to async does not
>>    run in a separate thread.  Rather, it runs at the time std::future.get()
>>    is called (not at the time the async is spawned).
>>
>>    Note, future defines:
>>
>>       enum class launch { any, async, sync };
>>
>>    It appears that the default is to use launch::any, but it's not clear
>>    to me what launch::any does.  Let me try specifying launch::async
>>    explicitly.
>>
>>    Okay, that works.  The code passed to async runs asynchronously,
>>    and task manager shows two additional threads (one for each async
>>    call) being spawned.
>>
>>    As expected, one call to async returns normally, and the second throws
>>    an exception.  This exception in rethrown correctly in the main thread
>>    when the main thread calls std::future.get().
>>
>> I would imagine that running synchronously when spawning an async
>> with the default "launch::any" would count as a bug, but I haven't looked
>> in detail at what the standard says.
>>
>> If you spawn your async explicitly with the "launch::async" option, does
>> that fix your issue?  If so, we're probably seeing the same thing.
>
> Ha, it works on Linux now. Great thanks! I did not notice the launch
> parameter.
>
> This is what I found in N3337:

Well, you have more courage than I do,  Reading the standard often
makes my head hurt.

>   if policy & launch::deferred is non-zero — Stores DECAY_COPY
>   (std::forward<F>(f)) and DECAY_COPY (std::forward<Args>(args))... in
>   the shared state. These copies of f and args constitute a deferred
>   function.... The first call to a non-timed waiting function (30.6.4)
>   on an asynchronous return object referring to this shared state
>   shall invoke the deferred function in the thread that called the
>   waiting function. Once evaluation of INVOKE (g, xyz) begins, the
>   function is no longer considered deferred. [ Note: If this policy is
>   specified together with other policies, such as when using a policy
>   value of launch::async | launch::deferred, implementations should
>   defer invocation or the selection of the policy when no more
>   concurrency can be effectively exploited. — end note ]
>
> I assume launch::any equals to launch::async | launch::deferred, and
> launch::sync is the old name of launch::deferred. It seems the C++11
> standard allows the GCC behaviour under a condition ("when no more
> concurrency can be effectively exploited"). Probably GCC 4.8 will
> improve on this.

Your analysis makes it sound like the behavior we're seeing is
technically legal, if not optimal.  ("Quality of implementation,"
as they say.)

One possibly related item, and speaking form vague memory:
I seem to recall that there is some kind of number-of-processors
call defined in the new standard,  I also seem to recall that when
I was playing around with the threading stuff, the various versions
of gcc that I was working with had it defaulted (legally) to "0" (or
some other not-available value).

Perhaps the vacuous value for the number of processors triggered
the "when no more concurrency can be effectively exploited" logic
you found mentioned in the standard.  Anyway, pure speculation
on my part.

(I should note that I ran my tests on a two-core machine, and was
able to verify running with concurrency when I used the launch::async
option.)

If I get bored, I might try the test again on a native mingw-w64 4.7
build I have.  I am also thinking about upgrading to 4.8, so I could
try it there, as well.

> Wu Yongwei

Thanks for the analysis.


K. Frank

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe