From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id 538ED2F27A for ; Wed, 8 Nov 2000 15:22:39 -0500 (EST) Received: (from mail@localhost) by mail.redhat.com (8.11.0/8.8.7) id eA8KMde15998 for axp-list@listman.redhat.com; Wed, 8 Nov 2000 15:22:39 -0500 Received: from toronto.sigma6.com (toronto.sigma6.com [204.176.48.147]) by mail.redhat.com (8.11.0/8.8.7) with ESMTP id eA8KMcD15994 for ; Wed, 8 Nov 2000 15:22:38 -0500 Received: from appnet.com (IDENT:jsturm@localhost.localdomain [127.0.0.1]) by toronto.sigma6.com (8.9.3/8.9.3) with ESMTP id PAA08613 for ; Wed, 8 Nov 2000 15:32:23 -0500 Message-ID: <3A09B857.79DB9BB2@appnet.com> Date: Wed, 08 Nov 2000 15:32:23 -0500 From: Jeff Sturm Organization: Commerce One X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.16 i686) X-Accept-Language: en MIME-Version: 1.0 To: axp-list@redhat.com Subject: Re: [Fwd: Alpha SMP problem] References: <3A095A5D.A5C7900D@scs.ch> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0beta4 Precedence: bulk Reply-To: axp-list@redhat.com List-Id: Linux and Red Hat on Alpha processors 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