From owner-freebsd-current Fri Sep 6 10:58: 7 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 358C237B400 for ; Fri, 6 Sep 2002 10:58:03 -0700 (PDT) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id ED85B43E4A for ; Fri, 6 Sep 2002 10:58:02 -0700 (PDT) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id CA0BDAE147; Fri, 6 Sep 2002 10:58:02 -0700 (PDT) Date: Fri, 6 Sep 2002 10:58:02 -0700 From: Alfred Perlstein To: Michal Mertl Cc: current@freebsd.org Subject: Re: bug in sysv semaphores on -CURRENT Message-ID: <20020906175802.GE21806@elvis.mu.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG * Michal Mertl [020906 06:10] wrote: > There seems to be bug in $SUBJ. When I run attached program on recent > -CURRENT, it always (after several seconds) triggers the bug. I first > suspected a problem in the program's logic but on stable in runs just > fine. > > Esentially I use piece of shm memory to pass some data between several > processes. I implemented simple locking functions with semaphores and > noticed it behaves strange on -CURRENT and ok on -STABLE. > > CCing Alfred because he made some changes into the kernel part of $SUBJ. I > don't expect the bug is new though. > > May I ask someone with older -CURRENT to try running the program for a > minute? I found your bug. In the function ipc_unlock() you do this: > int > ipc_unlock(void) > { > struct sembuf sem_buf; > int err; > > if (ipc_cfg->sem_owner != getpid()) { > fprintf(stderr, "%d: can't unlock (bug), owner: %d\n", > getpid(), ipc_cfg->sem_owner); > return (-1); > } > if (semctl(ipc_cfg->sem_id, 0, GETVAL) != 0) { > fprintf(stderr, "%d: can't unlock (bug), not locked\n", > getpid()); > return (-1); > } > printf("%d: ipc_unlock()\n", getpid()); > sem_buf.sem_num = 0; > sem_buf.sem_op = 1; > sem_buf.sem_flg = 0; > err = semop(ipc_cfg->sem_id, &sem_buf, 1); > if (err == -1) { > fprintf(stderr, "%d: semop()\n", getpid()); > return (-1); > } > ipc_cfg->sem_owner = -1; > return (0); > } Problem is that you're messing with lock state after dropping your semaphore! If you move the ipc_cfg->sem_owner = -1; to before the semop() call it seems to fix things. -Alfred To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message