SDL with linuxthreads

Is there any issues with using SDL and linuxthreads instead of NPTL (Native
Posix Thread Library)?

This is my test system kernel version and glibc version:—
Linux version 2.6.18.1

GNU C Library stable release version 2.3.2, by Roland McGrath et al.
Compiled by GNU CC version 3.4.2 (release) (CodeSourcery ARM Q3D 2004).
Compiled on a Linux 2.6.0-test7 system on 2005-11-03.
Available extensions:
GNU libio by Per Bothner
crypt add-on version 2.1 by Michael Glad and others
linuxthreads-0.10 by Xavier Leroy
BIND-8.2.3-T5B
libthread_db work sponsored by Alpha Processor Inc
NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk

======================================
In my application I am using SDL 1.2.11 with Paragui.

I found this weird behaviour:

I create a new “process” using fork(), then run this command:

while (true) {
system(“ls”);
system(“df”);
system(“free”);
system(“ls -l”);
sleep(3);
}

Everything runs fine as usual. These system commands will just run on the
background.

Now, I create a new “thread” using pthread, then run this command:

while (true) {
system(“ls”);
system(“df”);
system(“free”);
system(“ls -l”);
sleep(3);
}

Application will CRASH within 30 minutes. Sometimes within 5 minutes. It will
crash with exit code 0.

Anybody knows why this is happening?

Thanks.

Application will CRASH within 30 minutes. Sometimes within 5 minutes. It will
crash with exit code 0.

We’d need to see the backtrace in gdb, or at least the source code when
you create the thread. I don’t see any reason it should crash there,
based on the information I have; maybe it’s crashing somewhere else?

–ryan.

Ryan C. Gordon <icculus icculus.org> writes:

Application will CRASH within 30 minutes. Sometimes within 5 minutes. It will
crash with exit code 0.

We’d need to see the backtrace in gdb, or at least the source code when
you create the thread. I don’t see any reason it should crash there,
based on the information I have; maybe it’s crashing somewhere else?

–ryan.

Ryan, thanks for the interest in this problem.

Thread is created like this, pretty straight forward:==================================================================
// global static var.
static pthread_t testThread;

// thread function.
static void* threadFunction(void* args) {
int rVal = 0;
sleep(10);
while (true) {
rVal = system(“df -h”);
rVal = system(“ls”);
rVal = system(“route -n”);
rVal = system(“ifconfig”);
rVal = system(“ls -l”);
rVal = system(“free”);
sleep(3);
}
pthread_exit(0);
return (void*)NULL;
}

// this code executed after application is running.
pthread_create(&testThread, NULL, threadFunction, (void*)NULL);

Yes, I don’t think the thread code is crashing, but it is causing something to
crash. If I run the exact same “system()” commands from a “forked” process,
instead of using threads, application will run just fine. Also, when it crashes
it will exit with code “0”.

I am also using SDL Timers in my application.

Exact same system commands will crash the application when it is run from a
thread and it will never crash when it is run from a forked process.

So, thought maybe it is related to the thread model I’m using.

… Sam.

So, thought maybe it is related to the thread model I’m using.

Have you tried with a standalone application without SDL?

Have you tried with SDL’s threads?

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Sam Lantinga <slouken devolution.com> writes:

Have you tried with a standalone application without SDL?

Never crashes on standalone application. You can make system calls all you want
from both threads or forked processes.

Have you tried with SDL’s threads?

Yes, I tried it with SDL’s threads. Same thing like pthreads, it will crash
pretty fast.

Is it possible that signal is interfering with SDL’s timer. I’ll have to test
more, but I think if I don’t use SDL’s timer it works fine.

But I need to use SDL’s TIMER.

Also, same code never crashes on a Linux system that is using NPTL (Native Posix
Thread Library).

… Sam.

Are you sure its not an issue elsewhere in the program? If you omit
the system() calls, does your program still crash?

SDL_Timers can run in separate threads. Perhaps you are getting
synchronisation issues, and/or memory corruption due to improperly
shielded shared data access.

Can you show the source to a minimal example that demonstrates this?On 07/08/07, Sam wrote:

Is it possible that signal is interfering with SDL’s timer. I’ll have to test
more, but I think if I don’t use SDL’s timer it works fine.

But I need to use SDL’s TIMER.

Also, same code never crashes on a Linux system that is using NPTL (Native Posix
Thread Library).

… Sam.

Brian <brian.ripoff gmail.com> writes:

Are you sure its not an issue elsewhere in the program? If you omit
the system() calls, does your program still crash?

No it does not crash without these system calls. Also, if the systems calls are
being made from a separate forked process, it will never crash.

SDL_Timers can run in separate threads. Perhaps you are getting
synchronisation issues, and/or memory corruption due to improperly
shielded shared data access.

Can you show the source to a minimal example that demonstrates this?

Let me try to make a minimal example.

Thanks.

… Sam.