c++ - Is it OK to call std::async at high frequency? -


I have a small program that says that using std :: async for parallelism And it's crashing on me I'm pretty sure there are better ways to do this, but I just want to know what's going on here. I am not posting the exact code because I do not think it actually makes a difference. It basically looks something like this:

  while (1) {std :: vector & lt; Things & gt; Things (256); Auto update_th_things = [& amp; (Integer start, int end) {// some code}; Auto handle1 = std :: async (std :: launch :: async, update_the_things, 0, things.size () / 4); Auto handle2 = std :: async (std :: launch :: async, update_the_things, things.size () / 4, things size () / 4 * 2); Auto handle3 = std :: async (std :: launch :: async, update_the_things, things.size) / 4 * 2, things. Size () / 4 * 3); Update_the_things (things.size () / 4 * 3, things.size ()); Handle1.get (); Handle2.get (); Handle3.get (); }  

This loop runs several thousand times per second and crashes after random time (5 seconds - 1 minute). If I look at the Task Manager then I think thread count is increasing for this program, so I think std :: async is launching new threads with each call . I would have thought that it would work with a thread pool or some things, in any case, is it crashing because I am doing something wrong?

Using GDB I get the following:

  Program received signal SIGSEGV, switching to segmentation fault [Thread 3560.0x107 C] 0x0000000000000000 in ?? () # 0x0000000000000000 in ?? () # 1 0x000000000041d18c in pthread_create_wrapper () # 2 0x0000000000000000 in ?? ()  

Output from GCC-V as a request:

  Use the built-in app COLLECT_GCC = GCC COLLECT_LTO_WRAPPER = c: / tdm-gcc- 64 / bin /../ libexec / gcc / x86_64-w64-mingw32 / 4.8.1 / lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: .. /../../src/gcc -4.8.1 / configure --build = x86_64-w64-mingw32 - enabled-target = all - enabled languages ​​= ada, c, c ++, foreign, lto, ozgec, obj-c ++ --enable -libgomp --enable-lto --enable-graphite --enable-cxx-flags = -DWINPTHREAD_STATIC --enable-libstdcxx-debug --enable-threads = posix --enable-version-specific-runtime-libs --enable -fully-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx- Time-by-gnome U-ld --disable-werror --disable-nls --disable-win32-registry --prefix = / mingw64tdm --with-local-prefix = / mingw64tdm --with-pkgversion = tdm64-2 --with-bugurl = Http: //tdm-gcc.tdragon.net/bugs thread model: posix gcc version 4.8.1 (tdm 64-2)  

This standard-compliant program also crashes, and is usually very fast:

#include & lt; Iostream & gt; # Include & lt; Future & gt; Int main () {try {for (;;) {std :: async (std :: launch :: async, [] {}). () get receive; }} Hold (...) {std :: cout & lt; & Lt; "Throwed Some \ n"; }}

This is a bug in implementation.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -