From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 10 00:52:52 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B617163C; Wed, 10 Jun 2015 00:52:52 +0000 (UTC) (envelope-from rcarter@pinyon.org) Received: from quine.pinyon.org (quine.pinyon.org [65.101.5.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8E4281B20; Wed, 10 Jun 2015 00:52:52 +0000 (UTC) (envelope-from rcarter@pinyon.org) Received: by quine.pinyon.org (Postfix, from userid 122) id 0F5001602CD; Tue, 9 Jun 2015 17:52:51 -0700 (MST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on quine.pinyon.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Received: from feyerabend.n1.pinyon.org (feyerabend.n1.pinyon.org [10.0.10.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by quine.pinyon.org (Postfix) with ESMTPSA id 931EC16014F; Tue, 9 Jun 2015 17:52:48 -0700 (MST) Message-ID: <55778A60.9090200@pinyon.org> Date: Tue, 09 Jun 2015 17:52:48 -0700 From: "Russell L. Carter" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Daniel Eischen CC: freebsd-hackers@freebsd.org Subject: Re: umtx_lock and friends References: <55777108.5020206@pinyon.org> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jun 2015 00:52:52 -0000 Hi Daniel, On 06/09/15 16:57, Daniel Eischen wrote: > On Tue, 9 Jun 2015, Russell L. Carter wrote: > >> Hi, >> >> I'm investigating what the most lightweight inter-process mutex >> technique on FreeBSD and have been looking at the >> infrastructure in /usr/include/sys/umtx.h >> >> However, my simple test program fails to link: >> >> #include >> #include >> #include >> #include >> #include >> >> int main(int, char **) >> { >> printf("Testing..."); >> struct umtx m; >> umtx_init(&m); >> u_long id=5; >> umtx_lock(&m, id); >> umtx_unlock(&m, id); >> printf("Test done."); >> return 0; >> } >> >> produces the following: >> >> tester.cpp:(.text+0x36): undefined reference to `_umtx_lock(umtx*)' >> tester.cpp:(.text+0x5f): undefined reference to `_umtx_unlock(umtx*)' >> >> I've tried linking against a variety of suspects in /usr/lib but >> no luck. >> >> go-lang uses _umtx_op but they make the syscall directly via asm, >> it seems. >> >> I can build an inter-process mutex over semaphores but the umtx >> stuff looks perfect if I can get it to work. > > I'm not sure you are really suppose to be using those directly. > They are provided for FreeBSD's libraries (libthr) to use. But libthr doesn't support inter-process mutexes, correct? Here's the relevant excerpt from pthread_rwlockattr_setpshared(3): "BUGS The PTHREAD_PROCESS_SHARED attribute is not supported." > If they are meant for public consumption, I don't like how they > are implemented as static inlines in sys/umtx.h - it's not > possible to properly bind to these functions from non-C > languages. > > But, nonetheless, your example compiles and runs just fine as > a C program on FreeBSD 10-stable. > On FreeBSD 10-stable r283752 amd64, here is the compile line: /usr/bin/cc -O -Wall tester.cpp -o tester /tmp/tester-b681b3.o: In function `main': tester.cpp:(.text+0x35): undefined reference to `_umtx_lock(umtx*)' tester.cpp:(.text+0x5c): undefined reference to `_umtx_unlock(umtx*)' Compilers don't matter, linking against libthr or libstdthreads doesn't matter. Thanks, Russell