From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 15 17:48:04 2005 Return-Path: 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 B6D8216A4CE; Tue, 15 Mar 2005 17:48:04 +0000 (GMT) Received: from vms048pub.verizon.net (vms048pub.verizon.net [206.46.252.48]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8BF7F43D4C; Tue, 15 Mar 2005 17:48:04 +0000 (GMT) (envelope-from ringworm01@gmail.com) Received: from ringworm.mechee.com ([4.27.46.32]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IDE00J9SMS3DER0@vms048.mailsrvcs.net>; Tue, 15 Mar 2005 11:48:03 -0600 (CST) Received: by ringworm.mechee.com (Postfix, from userid 1001) id 7A6412CE75B; Tue, 15 Mar 2005 09:48:02 -0800 (PST) Date: Tue, 15 Mar 2005 09:48:01 -0800 From: "Michael C. Shultz" In-reply-to: To: Daniel Eischen , freebsd-hackers@freebsd.org Message-id: <200503150948.01624.ringworm01@gmail.com> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7bit Content-disposition: inline References: User-Agent: KMail/1.7.2 Subject: Re: threads question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Mar 2005 17:48:04 -0000 On Monday 14 March 2005 08:57 pm, Daniel Eischen wrote: > On Mon, 14 Mar 2005, Michael C. Shultz wrote: > > Hi, I've just reached a point in a program I'm writing where I'd > > like to do threading. > > > > When I try to start a thread like this: > > > > pthread_create(&thread, &attr, MGPMrUpgrade, property ); > > ^^^^^^^^ &property > > You should compile with -Wall and get rid of any warnings. > > > where property is a structure of many variables it doesn't get > > passed to the function. If I do this: > > > > pthread_create(&thread, &attr, MGPMrUpgrade( &property ), NULL ); > > That looks like it will actuall call MGPMrUpgrade() and use its > return value as the function pointer. > > > It works, but just seems wrong. > > > > Can anyone point me to a source file, preferably in /usr/src > > somewhere that passes a structure to a function being run as a > > thread so I may study the proper way to do this? > > src/lib/libpthread/test/sem_d.c > src/lib/libpthread/test/mutex_d.c > src/lib/libpthread/test/sigwait_d.c > > I'd suggest getting Butenhof's "Programming with POSIX Threads" book. Daniel, sorry to bother you again but I ran into something that is either a bug or I am missing a vital piece of information somewhere. Here is the situation: this works perfectly because I moved MGPMrUpgrade into the same .c file so it would be a static function: structProperty* property; pthread_t threads[NTHREADS]; pthread_create( &threads[0], NULL, zzMGPMrUpgrade, property ); When I use MGPMrUpgrade from a shared library the function runs yet property isn't being passed! I remember from assembly days that there were some stack tricks to be done when making calls to a shared library in order to pass the parameters, I forget what they are (been ages since I did assembly programming) but anyways it seems like with gcc passing the args through the stack to a function in a shared library isn't being handled correctly. Am I missing something obvious? -Mike