Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Jeff Sturm <jeff.sturm@appnet.com>
To: axp-list@redhat.com
Subject: Re: [Fwd: Alpha SMP problem]
Date: Wed, 08 Nov 2000 15:32:23 -0500	[thread overview]
Message-ID: <3A09B857.79DB9BB2@appnet.com> (raw)
In-Reply-To: 3A095A5D.A5C7900D@scs.ch

Reto Baettig wrote:
> The strange thing is that a single instance of the program runs just
> fine. When I start the program a second time, I get segfaults and/or
> stuck threads.

Actually I would expect stuck threads:

        mem.delete = 1;

        while (mem.delete)
            Th_Delay(1);

mem.delete must be declared `volatile' to prevent that from looping forever. 
However as long you didn't compile with optimizations you can probably get by.

Also, consider that the "Free" thread is writing:

        mem->buf = NULL;
        mem->delete = 0;
	// ...loop...

while the "DoTest" thread is reading:

	// ...loop....
        mb();
        assert(mem.buf == NULL);
        assert(mem.delete == 0);

The writes to mem->buf and mem->delete may be reordered by the compiler and/or
CPU.  Despite the memory barrier, DoTest can see a non-NULL mem.buf even after
it sees (mem.delete == 0).

To get guaranteed sequential behavior, you need to use `volatile' and a few more
membar's, e.g.:

        mem->buf = NULL;
	mb();
        mem->delete = 0;
	mb();

and:

        mem.buf = malloc(len);
        assert(mem.buf != NULL);
	mb();

        th_req[Th_Num]++;

        mem.delete = 1;
	mb();

or save yourself the trouble and use a mutex instead.

Honestly I didn't try your program, but I wouldn't consider blaming the kernel
or glibc as long as your code is incorrect.

--
Jeff Sturm
jeff.sturm@commerceone.com




  reply	other threads:[~2000-11-08 20:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-08 13:51 [Fwd: Alpha SMP problem] Reto Baettig
2000-11-08 20:32 ` Jeff Sturm [this message]
2000-11-08 16:51   ` Reto Baettig
2000-11-08 22:44     ` Jeff Sturm
2000-11-09  6:11       ` should I use 8 DIMMs for UP2000 M/B when I put two 667Mhz processors? Jeong Hwan Park
2000-11-09  1:31         ` W Bauske
2000-11-09  6:31           ` Jeong Hwan Park
2000-11-09  2:09             ` W Bauske
2000-11-09  7:04               ` Greg Lindahl
2000-11-09  3:21                 ` W Bauske
2000-11-09 15:36                   ` Greg Lindahl
2000-11-09 20:49                     ` W Bauske
2000-11-10  3:10                       ` Greg Lindahl
2000-11-09 23:36                         ` W Bauske
2000-11-09 20:18         ` Tom Heibel
2000-11-09 20:25           ` Rich Payne
2000-11-09 20:24         ` Tom Heibel
2000-11-08 22:15   ` [Fwd: Alpha SMP problem] Richard Henderson
2000-11-08 17:39     ` Reto Baettig
2000-11-08 23:53     ` Jeff Sturm
2000-11-09  1:56       ` Richard Henderson
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox