Date: Tue, 9 Jun 2015 19:57:36 -0400 (EDT) From: Daniel Eischen <deischen@freebsd.org> To: "Russell L. Carter" <rcarter@pinyon.org> Cc: freebsd-hackers@freebsd.org Subject: Re: umtx_lock and friends Message-ID: <Pine.GSO.4.64.1506091940001.10480@sea.ntplx.net> In-Reply-To: <55777108.5020206@pinyon.org> References: <55777108.5020206@pinyon.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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. 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.1506091940001.10480>