umtx_lock and friends

Russell L. Carter rcarter at pinyon.org
Tue Jun 9 23:13:55 UTC 2015


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.

Thanks,
Russell


More information about the freebsd-hackers mailing list