From owner-freebsd-threads@freebsd.org Wed Feb 17 16:16:24 2016 Return-Path: Delivered-To: freebsd-threads@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 717F2AAB431 for ; Wed, 17 Feb 2016 16:16:24 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 544C81CB9 for ; Wed, 17 Feb 2016 16:16:24 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: by mailman.ysv.freebsd.org (Postfix) id 516CAAAB42F; Wed, 17 Feb 2016 16:16:24 +0000 (UTC) Delivered-To: threads@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 50F46AAB42D; Wed, 17 Feb 2016 16:16:24 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C44B11CB7; Wed, 17 Feb 2016 16:16:23 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id u1HGGC04088915 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 17 Feb 2016 18:16:13 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua u1HGGC04088915 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id u1HGGCOq088914; Wed, 17 Feb 2016 18:16:12 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 17 Feb 2016 18:16:12 +0200 From: Konstantin Belousov To: Martin Simmons Cc: vangyzen@FreeBSD.org, threads@FreeBSD.org, arch@FreeBSD.org Subject: Re: libthr shared locks Message-ID: <20160217161612.GL91220@kib.kiev.ua> References: <20151223172528.GT3625@kib.kiev.ua> <56BE69B8.9020808@FreeBSD.org> <20160213143815.GB91220@kib.kiev.ua> <201602151417.u1FEHKwL003392@higson.cam.lispworks.com> <20160215144410.GT91220@kib.kiev.ua> <201602151735.u1FHZXKV006190@higson.cam.lispworks.com> <20160215175621.GU91220@kib.kiev.ua> <201602161617.u1GGHkil023634@higson.cam.lispworks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201602161617.u1GGHkil023634@higson.cam.lispworks.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Feb 2016 16:16:24 -0000 On Tue, Feb 16, 2016 at 04:17:46PM +0000, Martin Simmons wrote: > >>>>> On Mon, 15 Feb 2016 19:56:21 +0200, Konstantin Belousov said: > > > > One process which executed pthread_barrier_init(), performed what you > > proposed. What should do the pthread_barrier_wait() call in another > > process, which shares the 'barrier' with the first process, but does > > not share the whole address space ? After your pthread_barrier_init() > > executed, barrier contains the address of the object (off-page) in the > > other address space, for that process. > > Ah, sorry, I understand now (the init functions are called before any > sharing). Well, the memory is either already shared between processes, or it should become shared before other process may operate on the object carried by the memory. It is that pthread_mutex_init() must be called before any other pthread_mutex_*() functions, but only once globally. > > How should the destroy functions be used by the processes? I.e. should only > the "last" process call destroy or can every process call it? Hm, this is a good observation. pthread_mutex_destroy() must be called only by last process, i.e. no other pthread_mutex_* calls are allowed for the object after the _destroy() was called. What this means for my implementation, is that processes other than the _destroy() caller keep the record in the pshared cache, and this needs fixing. For now, I added a mechanism which scans the whole hash and re-checks the validity on any object destroy. This can be optimized, e.g. by doing the scan only each N calls to _destroy(), or by scanning only the same hash chain, or by not doing this at all. I think it is an acceptable compromise for now. A specific test for the case is at https://www.kib.kiev.ua/kib/pshared/pthread_shared_destroy.c Updated patch https://www.kib.kiev.ua/kib/pshared/pshared.4.patch