[libdispatch-dev] I missed the intro message ;)

Robert Watson rwatson at FreeBSD.org
Sat Sep 12 05:01:04 PDT 2009


On Sat, 12 Sep 2009, Matt Wright wrote:

>> - libdispatch_init is invoked directly by the libsyscall bootstrap in 
>> libSystem.  At least on FreeBSD, we can't just switch to an attribute 
>> constructor because of the way rtld performs locking around library init 
>> routines, so I'm pondering this still.  This is an issue for a Leopard port 
>> also.
>
> I have this in my own port too. For ease-of-bringup I opted to have the 
> users of my library call some initialisation calls at the very start of 
> their program. Specifically, one to start up the manager and worker threads 
> and then one to insert the main queue on the main thread's runloop.

Actually, turns out I misunderstood the bug I was seeing.  I had missed a bit 
of os_shims.h where libdispatch assumes it understands how TSD works on the 
platform, so directly accesses TSD data using assembly.  Switching to the 
portable version of this code fixed the memory corruption I'd previously 
attributed to out-of-order initialization.

So on FreeBSD, I've simply tagged libdispatch_init() as __attribute__ 
((constructor)).  This may well work on Leopard.

I'm now able to enter the dispatch run loop, and am on to tweaking FreeBSD's 
kqueue to pick up the required changes from Mac OS X.

Robert N M Watson
Computer Laboratory
University of Cambridge



More information about the libdispatch-dev mailing list