Thread performance (was Re: dynamic context transitions)

David Collier-Brown davec-b at rogers.com
Sun Dec 5 15:09:26 GMT 2004


tridge at samba.org wrote:
>  > ...
>  > 	The Solaris model is to assume programs are unthreaded, and 
>  > 	make it the programmer's responsibility to chose the thread-safe
>  > 	and high-threaded-performance interfaces, and no others. There
>  > 	are no locks or warnings about using a thread-unsafe libc function,
>  > 	it just fails at runtime.
> 
> lets test that theory:

	Sorry, but you have to choose a thread-unsafe interface
	to get it to fail: malloc says it's thread-safe, and there
	is a threaded malloc which is **supposed** to be fast.

	This is one of the **booby-traps** you have to look
	at the end of the man page for a table that says:
     ____________________________________________________________
   |        ATTRIBUTE TYPE       |        ATTRIBUTE VALUE      |
   | ____________________________|_____________________________|_
   |  Interface Stability        |  malloc(), calloc(), free(),|
   |                             |  realloc(),   valloc()   are|
   |                             |  Standard;  memalign()   and|
   |                             |  alloca() are Stable.       |
   |_____________________________|_____________________________|
   | MT-Level                    | Safe                        |
   |_____________________________|_____________________________|

	So if you try malloc, and assume that all other functions
	behave like malloc, you'll be surprised at runtime when
	you call getgrnam and find later that it said:

|    The  getgrnam(),  getgrgid(),  getgrent(),  and  fgetgrent()
|    functions  use  static  storage that is reused in each call,
|    making them unsafe for multithreaded applications.


	Net result: it's the the programmer's responsibility to chose the 
	thread-safe interfaces.  If it's unsafe, there really are **no**
	locks or warnings!

   To emphasize: "Anyone who writes a threaded program in C 
has just locked himself in to the vendor of the OS he used. 
If he needs to change vendors, he has to pay Dogbert".
  
   My old team used to make $250/hr for converting HP-UX and AIX
threaded programs to Slowlaris, and it was cheap at twice the 
price(;-))

  So: threads are like optimizations
Rule 1: don't optimize
Rule 2: if you must, do so **very** carefully

--dave
-- 
David Collier-Brown,         | Always do right. This will gratify
System Programmer and Author | some people and astonish the rest
davecb at spamcop.net           |                      -- Mark Twain


More information about the samba-technical mailing list