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

Re: [PATCH] fix threaded grep for machines with only one cpu

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 16, 2010, 01:07 UTC
Message-ID
<7vwryet2cw.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20100215225001.GA944@book.hvoigt.net>
Heiko Voigt <hvoigt@hvoigt.net> writes:
> In case the machine has only one cpu the initialization was
> skipped.

An obvious question that forces reviewers to go "Huh?" is why this matters.

If use_threads is false, we do not call start_threads(), and I think at least the intent of the threaded grep code in 5b594f4 (Threaded grep, 2010-01-25) is that uninitialized mutexes matter at all in that case.

For example, "grep_mutex" is touched by calling grep_lock() and grep_unlock() macros, or pthread_* functions on it directly. There are five functions that touch this mutex: add_work(), get_work(), work_done(), start_threads(), wait_all().

 - add_work() is called from grep_sha1_async() and grep_file_async().
   They are both called _only_ when use_threads is true.
 - get_work() and work_done() are only called from run() and that is the
   function threads run from start_threads().  They cannot be reached
   unless use_threads is true.
 - wait_all() has three call sites in cmd_grep(); all of them trigger only
   when use_threads is true.

So at least for grep_mutex your patch shouldn't matter. Please explain use of which mutex is broken and how your patch fixes it.

I think the fix also assumes that an initialized mutex that is used but not destroyed is not a programming error, as wait_all() is the ONLY function that destroys these mutexes and it is called ONLY when we are using threads by calling start_threads(). But that assumption surely smells like it is sweeping a bug under a rug rather than fixing it.

Is there some programming rule I am not aware of, like "if you define a mutex or cond, you must initialize it, even if you are not going to use it at all?" If that is the case, I think your patch is necessary, but I somehow find it a bit hard to believe.

Previous: Johannes SchindelinNext: Junio C Hamano
Message 3 of 26 in “fix threaded grep for machines with only one cpu”
  1. fix threaded grep for machines with only one cpuHeiko Voigt, Feb 15, 2010
  2. Johannes SchindelinFeb 15, 2010
  3. Junio C HamanoFeb 16, 2010
  4. Junio C HamanoFeb 16, 2010
  5. Junio C HamanoFeb 16, 2010
  6. Junio C HamanoFeb 16, 2010
  7. Fredrik KuivinenFeb 16, 2010
  8. Johannes SchindelinFeb 16, 2010
  9. Junio C HamanoFeb 16, 2010
  10. Johannes SchindelinFeb 17, 2010
  11. Junio C HamanoFeb 17, 2010
  12. Nicolas PitreFeb 17, 2010
  13. Heiko VoigtFeb 17, 2010
  14. Johannes SchindelinFeb 18, 2010
  15. Heiko VoigtFeb 16, 2010
  16. Nicolas PitreFeb 16, 2010
  17. Junio C HamanoFeb 16, 2010
  18. Sverre RabbelierFeb 16, 2010
  19. Nicolas PitreFeb 16, 2010
  20. Johannes SchindelinFeb 16, 2010
  21. Nicolas PitreFeb 16, 2010
  22. Heiko VoigtFeb 16, 2010
  23. Nicolas PitreFeb 16, 2010
  24. Junio C HamanoFeb 16, 2010
  25. Heiko VoigtFeb 17, 2010
  26. Paolo BonziniFeb 17, 2010

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.