From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 13 18:25:57 2007 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3246716A469 for ; Wed, 13 Jun 2007 18:25:57 +0000 (UTC) (envelope-from rick@kiwi-computer.com) Received: from kiwi-computer.com (keira.kiwi-computer.com [63.224.10.3]) by mx1.freebsd.org (Postfix) with SMTP id 839D513C469 for ; Wed, 13 Jun 2007 18:25:56 +0000 (UTC) (envelope-from rick@kiwi-computer.com) Received: (qmail 86764 invoked by uid 2001); 13 Jun 2007 18:25:55 -0000 Date: Wed, 13 Jun 2007 13:25:55 -0500 From: "Rick C. Petty" To: youshi10@u.washington.edu Message-ID: <20070613182555.GA86571@keira.kiwi-computer.com> References: <20070613162559.GA5093@britannica.bec.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i Cc: hackers@freebsd.org Subject: Re: Using shell commands versus C equivalents X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: rick-freebsd@kiwi-computer.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jun 2007 18:25:57 -0000 On Wed, Jun 13, 2007 at 10:23:36AM -0700, youshi10@u.washington.edu wrote: > On Wed, 13 Jun 2007, Joerg Sonnenberger wrote: > > Should I briefly lock (flock) the file when running open/fstat/fchmod then > to avoid issues? This may become a problem as pkg_*/make becomes more > parallelized (another student's goals for his SoC project). I wouldn't bother. What issue are you trying to avoid? If one process is trying to chmod +x and another is trying to do a chmod -x, it shouldn't matter if you lock between the fstat/fchmod-- someone is going to win anyway. This operation is not something that needs to be thread-safe. > Needless to say, pkg_* is by no means threadsafe in its current form > though. It uses some global vars that are currently not mutex locked, and > this type of file access is another issue (I wonder if spinlocking or > sleeping waiting for flock to finish would be better in this case). Does pkg_* use multiple threads? I was under the impression each pkg tool used a single thread (i.e. no threads) to do its operations and that they wait for system(2)-type calls as needed. Maybe I'm not clear by what you mean when you say "global vars". Now another question is whether the pkg_* tools can handle multiple processes managing the ports at the same time. For the mostpart, this is true. Without looking at the code, I would expect that the only contentions would be when trying to update the +REQUIRED_BY files. Everything else should be just fine; you're not supposed to be installing the same port multiple times at the exact same time, but maybe a lock could be held on the package directory (i.e. /var/db/pkg/$PKG_NAME). Again, I don't believe this is strictly necessary. -- Rick C. Petty