disable threads when recompiling libc

John Baldwin jhb at freebsd.org
Mon Dec 21 15:19:10 UTC 2009


On Monday 21 December 2009 2:15:13 am leon zadorin wrote:
> Hi,
> 
> is it possible to configure libc to be recompiled in a single-threaded
> model only (i.e. disable any additional overhead for handling
> thread-safety).
> 
> Basically what I'd like to do is to build a separate non-multithreaded
> copy of libc and use it with the rest of "single threaded
> environment":
> 
> recompiled gcc (./configure --disable-threads), etc.
> c++ boost libs in non-multithreaded mode and so on
> 
> I would like to see if there are any additional performance-benefits
> to this (my program does not need to be multi-threaded).
> 
> I think compiler itself can produce more optimisations (various
> speculative loads et al) if it is building code for single-threaded
> model only... I wonder if there are also "single-threaded" performance
> benefits to libc et al ?

libc already conditionalizes all the extra multi-thread protection on 
__isthreaded which only gets set to 1 the first time pthread_create() is 
invoked, so all you would be able to test is removing several 'if 
(__isthreaded)' tests.  You could perhaps make use of this to build a test 
libc though by #defining __isthreaded to 0 and relying on the compiler to 
eliminate all the conditional threading code as dead code.

-- 
John Baldwin


More information about the freebsd-threads mailing list