From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 10 00:05:14 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 90D26C38 for ; Wed, 10 Jun 2015 00:05:14 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from mail.netplex.net (mail.netplex.net [204.213.176.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.netplex.net", Issuer "RapidSSL SHA256 CA - G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 554421F4D for ; Wed, 10 Jun 2015 00:05:13 +0000 (UTC) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.netplex.net (8.15.1/8.15.1/NETPLEX) with ESMTP id t59Nvajw023874; Tue, 9 Jun 2015 19:57:36 -0400 X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.netplex.net) X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.4.3 (mail.netplex.net [204.213.176.9]); Tue, 09 Jun 2015 19:57:36 -0400 (EDT) Date: Tue, 9 Jun 2015 19:57:36 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net Reply-To: Daniel Eischen To: "Russell L. Carter" cc: freebsd-hackers@freebsd.org Subject: Re: umtx_lock and friends In-Reply-To: <55777108.5020206@pinyon.org> Message-ID: References: <55777108.5020206@pinyon.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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:05:14 -0000 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. 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. -- DE