This is the mail archive of the mailing list for the pthreas-win32 project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Bug report with source code attached

1) you didn't include the thread code, so we really don't
   know if all the threads are still consuming resources
   (and running!) or not. If they are you are chewing up
   all the system resources... there should be sufficient
   checks in both your code (and pthreads-win32) to deal
   with out of memory/resource errors (i.e. checking for
   failures of malloc, etc.)

2) the stack size should not be set at all when creating a
   pthread_attr... it should have been initialized to zero.
   WinNT will default the stack size of each thread to the
   size of the stack for the main process.. the default for
   that is 1Meg... don't worry... it isn't "committed" memory...
   it'll only acquire actual memory as needed, a page at a time.

   Seems there may be a bug here... Ross, you may want to
   verify that we are not initializing the stack size intentionally...
   we should let it default to the system defaults and not
   arbitrarily place limits implicitly.

-----Original Message-----
From: Dave Baggett []
Sent: Wednesday, March 01, 2000 2:55 AM
Subject: Bug report with source code attached

I have a sizeable pthreads-based server application that works well under
Linux and NT (using pthreads-win32). Under NT, however, it crashses
periodically. After several days of debugging, I have isolated the source of
the crashes to a small bit of code (included below) which looks to me to be
perfectly innocent. However, I may not understand pthreads semantics
adequately  -- it wouldn't be the first time --  so my code might be wrong.

If I compile the program below and run it with a "-l" argument ("l" as in
"lose"), I get:

  The instruction at "0x7800d557" referenced memory at "0x00000170".
  The memory could not be "written".

This happens after a delay that varies between 0 and 15 minutes.  The
instruction address never varies, but the referenced memory location
does. The debugger shows that it's dying in the malloc call in
pthread_attr_init. I.e., the heap is somehow getting corrupted.

If I run it without "-l", it seems to be able to run for hours without
crashing. Am I correct in assuming that the two modes of operation should
be equivalent (aside from the fact that I might be leaking memory by
not freeing the attrs)?

This happens with the 1999-11-02 snapshot as well as the 1999-09-17

I see nothing in the win32-pthreads source that looks like it could cause
However, I did notice that pthread_attr_init() returns you an attr that sets
the stacksize to 1K, which doesn't seem good. Explicitly setting the
won't fix the crash problem, but it still seems like you ought to default
stack to 256K or something reasonable.

Apologies in advance if I'm just doing something stupid. :)

Dave Baggett
// Call with -l argument to cause a crash.
// Compiled with MSVC6 using these args:
//   -nologo -D WIN32 -D _WINDOWS -ML -MTd -GX -Od -G6 -W3 -Zi
#include "pthread.h"
#include <assert.h>

void *NOP(void *p) { return NULL; }

main(int argc, char **argv)
    bool lose = (argc == 2 && !strcmp(argv[1], "-l"));
    for (;;) {
        int retval;
        pthread_t tid;

        if (lose) {
            pthread_attr_t attr;
            retval = pthread_attr_init(&attr);
            assert(retval==0);          // success
            retval = pthread_attr_setdetachstate(&attr,
            assert(retval==0);          // success
            retval = pthread_create(&tid, &attr, NOP, NULL);
        else {
            retval = pthread_create(&tid, NULL, NOP, NULL);
            assert(retval==0);          // success
            retval = pthread_detach(tid);
    return 0;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]