git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] compat: Allow static initializer for pthreads on Windows

From
Jeff King <peff@peff.net>
Date
Oct 27, 2016, 17:11 UTC
Message-ID
<20161027171121.tsg2gy5gov5apihq@sigill.intra.peff.net>
In-Reply-To
<CAGZ79kbP3pgPHgv-x1Q-Q1QwmXc=gOyxWhXh2SngO8WSZc3PFA@mail.gmail.com>
On Thu, Oct 27, 2016 at 10:01:02AM -0700, Stefan Beller wrote:
Show 5 quoted lines
> >  That function can
> > be called from main() of platforms that cannot statically initialize
> > mutices,
> 
> By main you mean the main() in common-main.c or cmd_main in git.c ?

Any setup or initialization for library functions needs to go in main() of common-main.c. Otherwise, only builtins get it, and external programs are left to segfault (or whatever).

> Those both look like the wrong place. Of course it would work adding it
> there, but it smells like a maintenance nightmare.

I agree it's ugly, but I suspect it would work OK in practice. We don't have that many mutexes and initializing them is cheap.

Languages like C++ have non-constant initializers, and the compiler takes care of running the startup code before main() begins. There's no portable way to do that in C, but our cmd_main() is roughly the same thing.

I still prefer the lazy initialization if it can work without incurring measurable overhead. That's the normal way to do things in C; the only complication here is the thread safety.

-Peff
Previous: Stefan BellerNext: Johannes Sixt
Message 10 of 28 in “compat: Allow static initializer for pthreads on Windows”
  1. compat: Allow static initializer for pthreads on WindowsStefan Beller, Oct 26, 2016
  2. Stefan BellerOct 26, 2016
  3. Johannes SixtOct 27, 2016
  4. Junio C HamanoOct 27, 2016
  5. Johannes SixtOct 27, 2016
  6. Junio C HamanoOct 27, 2016
  7. Johannes SixtOct 27, 2016
  8. Junio C HamanoOct 27, 2016
  9. Stefan BellerOct 27, 2016
  10. Jeff KingOct 27, 2016
  11. Johannes SixtOct 27, 2016
  12. Junio C HamanoOct 27, 2016
  13. Stefan BellerOct 27, 2016
  14. Johannes SixtOct 27, 2016
  15. Jacob KellerOct 27, 2016
  16. Stefan BellerOct 27, 2016
  17. Johannes SixtOct 28, 2016
  18. Jacob KellerOct 28, 2016
  19. Philip OakleyOct 28, 2016
  20. Jacob KellerOct 28, 2016
  21. Johannes SchindelinOct 28, 2016
  22. Jacob KellerOct 28, 2016
  23. Johannes SixtOct 28, 2016
  24. Junio C HamanoOct 28, 2016
  25. Stefan BellerOct 28, 2016
  26. Junio C HamanoOct 28, 2016
  27. Johannes SixtOct 28, 2016
  28. Junio C HamanoOct 28, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.