Date: Tue, 09 Jun 2015 17:52:48 -0700 From: "Russell L. Carter" <rcarter@pinyon.org> To: Daniel Eischen <deischen@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: umtx_lock and friends Message-ID: <55778A60.9090200@pinyon.org> In-Reply-To: <Pine.GSO.4.64.1506091940001.10480@sea.ntplx.net> References: <55777108.5020206@pinyon.org> <Pine.GSO.4.64.1506091940001.10480@sea.ntplx.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h> >> #include <sys/types.h> >> #include <machine/atomic.h> >> #include <errno.h> >> #include <sys/umtx.h> >> >> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?55778A60.9090200>