From owner-freebsd-hackers Tue Jan 28 23:51:39 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 823E537B401 for ; Tue, 28 Jan 2003 23:51:38 -0800 (PST) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id EE9B843F3F for ; Tue, 28 Jan 2003 23:51:37 -0800 (PST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.6/8.12.6) id h0T7pTNR081673; Wed, 29 Jan 2003 01:51:29 -0600 (CST) (envelope-from dan) Date: Wed, 29 Jan 2003 01:51:29 -0600 From: Dan Nelson To: Murat Balaban Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: memcpy and multithreading Message-ID: <20030129075129.GK17299@dan.emsphone.com> References: <20030129092714.A86300@enderunix.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030129092714.A86300@enderunix.org> X-OS: FreeBSD 5.0-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.3i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In the last episode (Jan 29), Murat Balaban said: > Are there any issues that i should now about memcpy and > multithreading in FreeBSD? I've got a code which reads: > > memcpy(&(h.req), req, sizeof(struct request)); What are the values of h and req at the time of segfault? You might want to try running with MALLOC_OPTIONS=J, which makes sure you don't accidentally use free'd memory, or assume that malloced memory is zeroed. If you see pointers with values near 0xD0D0D0D0, you have found a bug in your code... > and I keep getting SIGSEGV there in FreeBSD but not in Linux. > > PS: Of course, I protect the write operation with a mutex. Mutexes will protect you from someone stepping on your memory while you're copying. They don't protect you from seg faults if you have the wrong pointers in the first place. -- Dan Nelson dnelson@allantgroup.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message