Hello
I get a segfault when running even the most simple SDL program when using
OpenMP.
#include <SDL/SDL.h>
int main()
{
#pragma omp parallel num_threads(2)
{
SDL_Init(SDL_INIT_VIDEO);
}
return(0);
}
I compile with “g++ program.cpp -lSDL -fopenmp -g”, on Debian Sid:
g++ 4:4.3.1-2
libsdl1.2-dev 1.2.13-2
I want to have two threads that plot independently to different surfaces using
OpenGL, and I want to do this by using OpenMP. But even the code program
above segfaults.
Here is the output from valgrind:
==7697== Memcheck, a memory error detector.
==7697== Copyright © 2002-2007, and GNU GPL’d, by Julian Seward et al.
==7697== Using LibVEX rev 1854, a library for dynamic binary translation.
==7697== Copyright © 2004-2007, and GNU GPL’d, by OpenWorks LLP.
==7697== Using valgrind-3.3.1-Debian, a dynamic binary instrumentation
framework.
==7697== Copyright © 2000-2007, and GNU GPL’d, by Julian Seward et al.
==7697== For more details, rerun with: -v
==7697==
==7697== Jump to the invalid address stated on the next line
==7697== at 0x0: ???
==7697== by 0x4166D5B: (within /usr/lib/libSDL-1.2.so.0.11.1)
==7697== by 0x41549F5: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.1)
==7697== by 0x4128722: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.1)
==7697== by 0x4128786: SDL_Init (in /usr/lib/libSDL-1.2.so.0.11.1)
==7697== by 0x8048641: main.omp_fn.0
(in /home/tmac/programming/visualization/sdl/snowman.elf)
==7697== by 0x8048688: main
(in /home/tmac/programming/visualization/sdl/snowman.elf)
==7697== Address 0x0 is not stack’d, malloc’d or (recently) free’d
==7697==
==7697== Process terminating with default action of signal 11 (SIGSEGV)
==7697== Bad permissions for mapped region at address 0x0
==7697== at 0x0: ???
==7697== by 0x4166D5B: (within /usr/lib/libSDL-1.2.so.0.11.1)
==7697== by 0x41549F5: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.1)
==7697== by 0x4128722: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.1)
==7697== by 0x4128786: SDL_Init (in /usr/lib/libSDL-1.2.so.0.11.1)
==7697== by 0x8048641: main.omp_fn.0
(in /home/tmac/programming/visualization/sdl/snowman.elf)
==7697== by 0x8048688: main
(in /home/tmac/programming/visualization/sdl/snowman.elf)
==7697==
==7697== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 65 from 1)
==7697== malloc/free: in use at exit: 416 bytes in 7 blocks.
==7697== malloc/free: 7 allocs, 0 frees, 416 bytes allocated.
==7697== For counts of detected errors, rerun with: -v
==7697== searching for pointers to 7 not-freed blocks.
==7697== checked 9,049,520 bytes.
==7697==
==7697==
==7697== 152 bytes in 1 blocks are possibly lost in loss record 5 of 5
==7697== at 0x4021E22: calloc (vg_replace_malloc.c:397)
==7697== by 0x4010C7B: _dl_allocate_tls (in /lib/ld-2.7.so)
==7697== by 0x42FF672: pthread_create@@GLIBC_2.1
(in /lib/i686/cmov/libpthread-2.7.so)
==7697== by 0x42EAA0B: (within /usr/lib/libgomp.so.1.0.0)
==7697== by 0x42EA2BE: GOMP_parallel_start (in /usr/lib/libgomp.so.1.0.0)
==7697== by 0x804867C: main
(in /home/tmac/programming/visualization/sdl/snowman.elf)
==7697==
==7697== LEAK SUMMARY:
==7697== definitely lost: 0 bytes in 0 blocks.
==7697== possibly lost: 152 bytes in 1 blocks.
==7697== still reachable: 264 bytes in 6 blocks.
==7697== suppressed: 0 bytes in 0 blocks.
==7697== Reachable blocks (those to which a pointer was found) are not shown.
==7697== To see them, rerun with: --leak-check=full --show-reachable=yes
Killed
and the output from gdb after having compiled with -ggdb:
This GDB was configured as “i486-linux-gnu”…
(gdb) run
Starting program: /home/tmac/programming/visualization/sdl/snowman.elf
[Thread debugging using libthread_db enabled]
[New Thread 0xb7866900 (LWP 7693)]
[New Thread 0xb7865b90 (LWP 7696)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7866900 (LWP 7693)]
0x00000000 in ?? ()
Best regards
Torquil S?rensen