From owner-freebsd-threads@FreeBSD.ORG Thu Dec 24 01:20:30 2009 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CEF7A106566B; Thu, 24 Dec 2009 01:20:30 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id BD53A8FC16; Thu, 24 Dec 2009 01:20:30 +0000 (UTC) Received: from apple.my.domain (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id nBO1KSg6001520; Thu, 24 Dec 2009 01:20:29 GMT (envelope-from davidxu@freebsd.org) Message-ID: <4B32C1DC.9080308@freebsd.org> Date: Thu, 24 Dec 2009 09:20:28 +0800 From: David Xu User-Agent: Thunderbird 2.0.0.9 (X11/20080612) MIME-Version: 1.0 To: John Baldwin References: <4B317741.8080004@freebsd.org> <200912230936.35998.jhb@freebsd.org> In-Reply-To: <200912230936.35998.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: threads@freebsd.org, freebsd-threads@freebsd.org Subject: Re: first patch for process-shared semaphore X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 01:20:30 -0000 John Baldwin wrote: > On Tuesday 22 December 2009 8:49:53 pm David Xu wrote: >> This is my first attempt to make process-shared mutex work, this means >> you can mmap(MAP_SHARED) a memory area, and put semaphore there, >> or you can sem_open a named semaphore, and just use it between >> processes, the named semaphore uses file system and mmap(), directory >> /tmp/.semaphore is used as IPC directory, any named semaphore >> locates in the directory. old semaphore implementation still exists >> to make it binary compatible, it uses symbol version. >> >> http://people.freebsd.org/~davidxu/patch/shared_semaphore_1.patch > > I would suggest that you leave named semaphores as they currently exist and > follow this approach instead: > > 1) Named semaphores use ksem_*() still. > 2) sem_init/sem_destroy operate on UTMX-backed semaphores identical to the > ones used in the current libthr code. The semid_t structure now becomes the > full structure that libthr currently allocates with a flag to indicate if it > is a "system" semaphore or otherwise. The pshared flag passed to sem_init() > can be used to set the sharing properties of the UMTX. > 3) All of sem_init/sem_destroy is just in libc. Just move the libthr > implementation bits into libc. > ksem base shared semaphore is slow because whenever you call sem_wait(), it always enters kernel even if count is non-zero, sem_post() also always enters kernel even if there is no waiter. but the new implementation is as simple as just an atomic operation in these cases, I know another competitor OS is doing things in this way.