Multithreading & Win32

Hi all out there!

I’ve got a little problem! (what else)… :-;

I’m developing a multithreaded application under linux…
everything’s working fine…, i have multiple threads updating
the screen. allocating memory, …

everything’s nice, i said before…

BUT, when i compile my application under WinNT 4.0,
no weird annomalies occur …

BUT, when i run my application (under WinNT),…
I always get an GPF (General Protection Fault) if my
application is allocating memory (malloc).

This happens in the calls to SDL (e.q. SDL_CreateSurfaceRGB)
and in my own calls. (But only when i am trying to alloc the mem
from within a thread) !!!

YES,… I compiled the whole thing with the multithreaded libs
(VC6.0)

So,… if anyone has any idea …

I would be pleased to hear from you!

Alex

PS: YES,…
if you can’t understand my problem, …
if, my explaination was to poor…
if, you wanna get more details …
if, you are sure that you wanna help me …

PLEASE MAIL ME PRIVATELY :wink: OR TO THE LIST…
(maybe someone else has to fight the same problems)

mailto:@Alexander_Pipelka

I’m developing a multithreaded application under linux…
everything’s working fine…, i have multiple threads updating
the screen. allocating memory, …

BUT, when i run my application (under WinNT),…
I always get an GPF (General Protection Fault) if my
application is allocating memory (malloc).

One possibilty: Check for un-initialized variables. On Linux, any kind of
memory you don’t initialize is filled with zeros automatically. This isn’t
always true on NT… (I’m grateful though, since it’s revealed quite a few
bugs in my own code =)

Dan

Dan Maas wrote:

I’m developing a multithreaded application under linux…
everything’s working fine…, i have multiple threads updating
the screen. allocating memory, …

BUT, when i run my application (under WinNT),…
I always get an GPF (General Protection Fault) if my
application is allocating memory (malloc).

I don’t know much about NT, but in Unix, a SEGV in malloc()
usually indicates that a buffer over/underrun has occured.
It could be that your Linux environment is not as sensitive
to these conditions. I would try running the app under Linux,
using Electric Fence to try to flush out any errors.

I am assuming that your malloc implementation is thread-safe.

One possibilty: Check for un-initialized variables. On Linux, any kind of
memory you don’t initialize is filled with zeros automatically. This isn’t
always true on NT… (I’m grateful though, since it’s revealed quite a few
bugs in my own code =)

I don’t think this is true for Linux, especially with optimization
enabled in the compile. Also, malloc() does not initialize memory,
calloc() does that.

JW–
// John Watson
// Software Engineer – STScI Archive Team

You don’t need NT when you’ve got -Wall :-)–
Brian

One possibilty: Check for un-initialized variables. On Linux, any kind of
memory you don’t initialize is filled with zeros automatically. This isn’t
always true on NT… (I’m grateful though, since it’s revealed quite a few
bugs in my own code =)

Dan

On Linux, any kind of
memory you don’t initialize is filled with zeros automatically.
I don’t think this is true for Linux, especially with optimization
enabled in the compile. Also, malloc() does not initialize memory,
calloc() does that.

On Linux, any uninitialized data in the bss, as well as new memory from
malloc(), is mmap’ed from /dev/zero. So you’re guaranteed to get zeros in
all “correctly” allocated blocks - obviously a pointer mishap could result
in reading pretty much anything… Anyway, I’m pretty sure there is a class
of bugs that are hidden by the default Linux behavior…

Dan

On Linux, any uninitialized data in the bss, as well as new memory from
malloc(), is mmap’ed from /dev/zero.

Actually that’s not always true. If you allocate a small chunk, then malloc()
doesn’t necessarily need to get use sbrk() to get a new zeroed chunk, and so
returns memory that may already have administrative data or old memory info
in it. One of the best ways to catch uninitialized memory problems is to use
a memory implementation that initializes memory to non-zero values before
giving it to you (like dmalloc does)

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software