public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: "Bossom, John" <John.Bossom@Cognos.COM>
To: 'Dave Baggett' <dmb@itasoftware.com>,
	pthreads-win32@sourceware.cygnus.com
Subject: RE: Bug report with source code attached
Date: Wed, 01 Mar 2000 07:38:00 -0000	[thread overview]
Message-ID: <430F887D415DD1118C2700805F31ECF102E2F64E@sota0005.cognos.com> (raw)

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 [ mailto:dmb@itasoftware.com ]
Sent: Wednesday, March 01, 2000 2:55 AM
To: pthreads-win32@sourceware.cygnus.com
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
snapshot.

I see nothing in the win32-pthreads source that looks like it could cause
this.
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
stacksize
won't fix the crash problem, but it still seems like you ought to default
the
stack to 256K or something reasonable.

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

Dave Baggett
dmb@itasoftware.com
----------------------------------------------------------------------------
---
//
// 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; }

int
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,
PTHREAD_CREATE_DETACHED);
            assert(retval==0);          // success
            retval = pthread_create(&tid, &attr, NOP, NULL);
            assert(retval==0);
        }
        else {
            retval = pthread_create(&tid, NULL, NOP, NULL);
            assert(retval==0);          // success
            retval = pthread_detach(tid);
            assert(retval==0);
        }
    }
    return 0;
}

             reply	other threads:[~2000-03-01  7:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-01  7:38 Bossom, John [this message]
2000-03-01  9:54 ` Dave Baggett
  -- strict thread matches above, loose matches on Subject: below --
2000-03-02  7:46 Bossom, John
2000-03-02 16:15 ` Dave Baggett
2000-03-02  0:32 reentrant
2000-02-29 23:59 Dave Baggett
2000-03-01  1:10 ` Dave Baggett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=430F887D415DD1118C2700805F31ECF102E2F64E@sota0005.cognos.com \
    --to=john.bossom@cognos.com \
    --cc=dmb@itasoftware.com \
    --cc=pthreads-win32@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).