From owner-freebsd-threads@FreeBSD.ORG Thu Feb 6 01:26:44 2014 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D2F5A7E8 for ; Thu, 6 Feb 2014 01:26:44 +0000 (UTC) Received: from mout.web.de (mout.web.de [212.227.15.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6E314112E for ; Thu, 6 Feb 2014 01:26:44 +0000 (UTC) Received: from nil ([85.214.255.69]) by smtp.web.de (mrweb102) with ESMTPA (Nemesis) id 0MJkxE-1WCK7R40H6-001BBj for ; Thu, 06 Feb 2014 02:21:31 +0100 From: Luca Bayer To: John Baldwin Subject: Re: What is the status of thread process-shared synchronization? In-Reply-To: <201009231006.40019.jhb@freebsd.org> (John Baldwin's message of "Thu, 23 Sep 2010 10:06:39 -0400") Date: Thu, 06 Feb 2014 01:47:10 +0100 Message-ID: <20140206.86sirxgj8x@web.de> References: <201009231006.40019.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K0:JvGbUUl/7TkVwemsI24RE1aqBl7Tn+66T2sTsMjTm7TAMWjN+MW f3EB1vtjUWNKXMAzE887L6JVNoW1GWAIjF5Z7Ip+TMSp2SZdK00pL+rS32bZu4rj4CQ27jE UGLfvKx+NvJ/Vm+FkeJKhmtn9NLHB/KR4hBEDxGArHNXUXG4xgFpIBR7/UFzFgO3KB4F+wT KKeQcwjWnAz8f0LS13Ynw== Cc: Alexander Churanov , David Xu , freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Feb 2014 01:26:44 -0000 John Baldwin writes: >> Hi folks! >> >> The FreeBSD 8.1 manual pages state that pthread process-shared >> synchronization option is not supported, at least for some primitives. >> >> 1) Are there any plans to implement this option? >> 2) Is anybody working on that? >> 3) What are the main obstacles which prevent us from having the option >> implemented? >> >> I am teaching students UNIX-like systems in general and FreeBSD in >> particular. I've set them a task on synchronizing processes reading >> and writing from a shared-memory cache. But then found that in spite >> of PTHREAD_PROCESS_SHARED being available, it is not supported. I've >> endeavored to fix POSIX rwlocks by making pthread_rwlock_t a >> structure, but then found that POSIX semaphores do not support >> process-shared attribute either. > > I believe POSIX semaphores in 9 do now support PTHREAD_PROCESS_SHARED. David > Xu implemented it. He may be able to MFC this to 8-stable. I wonder what's the status of process-shared mutexes. They still don't work as compared to glibc (linux and kfreebsd). Here's a failing example http://www.andy-pearce.com/wiki/notes/sharing_pthreads_primitives_between_processes $ ./test ... About to fork. [0] PARENT: sleeping for 1 second. [0] CHILD: acquiring mutex. [0] CHILD: sleeping for 2 seconds. [1] PARENT: acquiring mutex [1] PARENT: waking child. [1] PARENT: waiting for child. [2] CHILD: waiting to be woken. load: 3.71 cmd: test 47522 [uwait] 17.86r 0.00u 0.00s 0% 2084k ^C where pthread_mutexattr_setpshared() actually returns EINVAL with PTHREAD_PROCESS_SHARED. It's also not possible to delay loading -lpthread due to missing pthread stubs in libc. > >> 4) Do we have any synchronization primitive capable of synchronizing >> threads in different processes in FreeBSD? > > Unfortunately the various POSIX/SYSV primitives do not currently support it in > 8. You could implement a shared mutex on top of umtx fairly easily I believe. > umtx itself is address-space agnostic (so a umtx object can be shared among > processes), and the existing pthread_mutex code can probably be borrowed > directly to implement a mutex. I think the biggest obstacle for FreeBSD is > changing the definition of pthread_mutex_t, etc. to be structures instead of > pointers to dynamically allocated structures.