digitalmars.D.learn - double free or corruption error when using parallel foreach
- Minas Mina (148/148) Dec 27 2012 Hi. I want to make my raytracer run in parallel. My idea is to
- FG (8/21) Dec 28 2012 This sheds some light on the problem.
Hi. I want to make my raytracer run in parallel. My idea is to use a parallel foreach. That's what I do: http://pastebin.com/V4zTKbVJ Note that there is more code after bool hit = ... but I didn't include it because the problem is in the trace function (I commented it out and everything else worked -- apart from the things are dependent on it of course) Also, scene is of type Scene, which is a struct. Sometimes I get this: Rendering... [xcb] Unknown request in queue while dequeuing [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called [xcb] Aborting, sorry about that. raytracing: ../../src/xcb_io.c:178: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed. bash: line 1: 18982 Aborted (core dumped) /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing Other times this: Rendering... *** glibc detected *** /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing: double free or corruption (fasttop): 0x0000000001ba4f30 *** bash: line 1: 19007 Aborted (core dumped) /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing And other times: Rendering... *** glibc detected *** /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing: double free or corruption (fasttop): 0x0000000001c22e40 *** *** glibc detected *** /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing: double free or corruption (fasttop): 0x0000000001c44d10 *** *** glibc detected *** /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing: double free or corruption (fasttop): 0x0000000001c44d10 *** ======= Backtrace: ========= ======= Backtrace: ========= ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7ff7f2d41b96] /lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7ff7f2d41b96] /lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7ff7f2d41b96] /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing(_D3std8typecons130__T10RefCountedTS3std9container40__T5ArrayTC10raytracing7surface7SurfaceZ5Array7PayloadVE3std8typecons24RefCountedAutoInitialize0Z10RefCounted6__dtorMFZv+0x3b/usr/lib/x86_64-linux-gnu/libSDL.so(+0x35012)[0x7ff7f2a61012] /usr/lib/x86_64-linux-gnu/libSDL.so(SDL_QuitSubSystem+0x95)[0x7ff7f2a364f5] /usr/lib/x86_64-linux-gnu/libSDL.so(SDL_Quit+0xe)[0x7ff7f2a3655e] /usr/lib/x86_64-linux-gnu/libSDL.so(+0xabaf)[0x7ff7f2a36baf] /lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0)[0x7ff7f3595cb0] 00400000-004d1000 r-xp 00000000 08:06 5648092 /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing 006d1000-006d2000 r--p 000d1000 08:06 5648092 /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing 006d2000-006e3000 rw-p 000d2000 08:06 5648092 /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing 006e3000-006e4000 rw-p 00000000 00:00 0 01bde000-01c57000 rw-p 00000000 00:00 0 [heap] 7ff7dc000000-7ff7dc021000 rw-p 00000000 00:00 0 7ff7dc021000-7ff7e0000000 ---p 00000000 00:00 0 7ff7e0000000-7ff7e0021000 rw-p 00000000 00:00 0 7ff7e0021000-7ff7e4000000 ---p 00000000 00:00 0 7ff7e4000000-7ff7e4021000 rw-p 00000000 00:00 0 7ff7e4021000-7ff7e8000000 ---p 00000000 00:00 0 7ff7e904c000-7ff7e904d000 ---p 00000000 00:00 0 7ff7e904d000-7ff7e984d000 rw-p 00000000 00:00 0 [stack:19036] 7ff7ebc20000-7ff7ebc35000 r-xp 00000000 08:06 5384474 /lib/x86_64-linux-gnu/libgcc_s.so.1 7ff7ebc35000-7ff7ebe34000 ---p 00015000 08:06 5384474 /lib/x86_64-linux-gnu/libgcc_s.so.1 7ff7ebe34000-7ff7ebe35000 r--p 00014000 08:06 5384474 /lib/x86_64-linux-gnu/libgcc_s.so.1 7ff7ebe35000-7ff7ebe36000 rw-p 00015000 08:06 5384474 /lib/x86_64-linux-gnu/libgcc_s.so.1 7ff7ebe36000-7ff7ebe37000 ---p 00000000 00:00 0 7ff7ebe37000-7ff7ec637000 rw-p 00000000 00:00 0 [stack:19038] 7ff7ec637000-7ff7ec638000 ---p 00000000 00:00 0 7ff7ec638000-7ff7ed679000 rw-p 00000000 00:00 0 [stack:19037] 7ff7ed679000-7ff7ed84e000 rw-s 00000000 00:04 6488069 /SYSV00000000 (deleted) 7ff7ed84e000-7ff7ed853000 r-xp 00000000 08:06 7365724 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0 7ff7ed853000-7ff7eda52000 ---p 00005000 08:06 7365724 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0 7ff7eda52000-7ff7eda53000 r--p 00/home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing(_D3std9container40__T5ArrayTC10raytracing7surface7SurfaceZ5Array7opIndexMFmZC10raytracing7surface7Surface+0x59)[0x481d0d] ======= Memory map: ======== 004000 08:06 7365724 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0 7ff7eda53000-7ff7eda54000 rw-p 00005000 08:06 7365724 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0 7ff7eda54000-7ff7eda5d000 r-xp 00000000 08:06 7356454 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0 7ff7eda5d000-7ff7edc5c000 ---p 00009000 08:06 7356454 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0 7ff7edc5c000-7ff7edc5d000 r--p 00008000 08:06 7356454 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0 7ff7edc5d000-7ff7edc5e000 rw-p 00009000 08:06 7356454 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0 7ff7edc5e000-7ff7edc67000 r-xp 00000000 08:06 7357883 /usr/lib/x86_64-linux-gnu/libXcursor.so.1.0.2 7ff7edc67000-7ff7ede67000 ---p 00009000 08:06 7357883 /usr/lib/x86_64-linux-gnu/libXcursor.so.1.0.2 7ff7ede67000-7ff7ede68000 r--p 00009000 08:06 7357883 /usr/lib/x86_64-linux-gnu/libXcurs00400000-004d1000 r-xp 00000000 08:06 5648092 /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing 006d1000-006d2000 r--p 000d1000 08:06 5648092 /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing 006d2000-006e3000 rw-p 000d2000 08:06 5648092 /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing 006e3000-006e4000 rw-p 00000000 00:00 0 01bde000-01c57000 rw-p 00000000 00:00 0 [heap] 7ff7dc000000-7ff7dc021000 rw-p 00000000 00:00 0 7ff7dc021000-7ff7e0000000 ---p 00000000 00:00 0 7ff7e0000000-7ff7e0021000 rw-p 00000000 00:00 0 7ff7e0021000-7ff7e4000000 ---p 00000000 00:00 0 7ff7e4000000-7ff7e4021000 rw-p 00000000 00:00 0 7ff7e4021000-7ff7e8000000 ---p 00000000 00:00 0 7ff7e904c000-7ff7e904d000 ---p 00000000 00:00 0 7ff7e904d000-7ff7e984d000 rw-p 00000000 00:00 0 [stack:19036] 7ff7ebc20000-7ff7ebc35000 r-xp 00000000 08:06 5384474 /lib/x86_64-linux-gnu/libgcc_s.so.1 7ff7ebc35000-7ff7ebe34000 ---p 00015000 08:06 5384474 /lib/x86_64-linux-gnu/libgcc_s.so.1 7ff7ebe34000-7ff7ebe35000 r--p 00014000 08:06 5384474 /lib/x86_64-linux-gnu/libgcc_s.so.1 7ff7ebe35000-7ff7ebe36000 rw-p 00015000 08:06 5384474 /lib/x86_64-linux-gnu/libgcc_s.so.1 7ff7ebe36000-7ff7ebe37000 ---p 00000000 00:00 0 7ff7ebe37000-7ff7ec637000 rw-p 00000000 00:00 0 [stack:19038] 7ff7ec637000-7ff7ec638000 ---p 00000000 00:00 0 7ff7ec638000-7ff7ed679000 rw-p 00000000 00:00 0 [stack:19037] 7ff7ed679000-7ff7ed84e000 rw-s 00000000 00:04 6488069 /SYSV00000000 (deleted) 7ff7ed84e000-7ff7ed853000 r-xp 00000000 08:06 7365724 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0 7ff7ed853000-7ff7eda52000 ---p 00005000 08:06 7365724 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0 7ff7eda52000-7ff7eda53000 r--p 00bash: line 1: 19033 Aborted (core dumped) /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracing
Dec 27 2012
On 2012-12-28 01:08, Minas Mina wrote:Note that there is more code after bool hit = ... but I didn't include it because the problem is in the trace function (I commented it out and everything else worked -- apart from the things are dependent on it of course)Why don't you show the trace function then? Where's the rest of the code?[xcb] Unknown request in queue while dequeuing [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called [xcb] Aborting, sorry about that. raytracing: ../../src/xcb_io.c:178: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed. bash: line 1: 18982 Aborted (core dumped) /home/minas/Projects/D/raytracing/raytracing/bin/Release/raytracingThis sheds some light on the problem. Probably it would go away if only a single thread was made responsible for calls into libxcb. That's a preferable, safer approach than initializing for multi-threading (but have you done the initializing?).double free or corruptionIMO that's just a consequence of several threads manipulating same data without any locks or synchronization in place.
Dec 28 2012