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

Re: [PATCHv2] attr: convert to new threadsafe API

From
Johannes Sixt <j6t@kdbg.org>
Date
Oct 12, 2016, 20:07 UTC
Message-ID
<44c554b8-7ac1-047d-59f0-b4d5331ed496@kdbg.org>
In-Reply-To
<20161011235951.8358-1-sbeller@google.com>
Am 12.10.2016 um 01:59 schrieb Stefan Beller:
Show 24 quoted lines
> +void git_attr_check_initl(struct git_attr_check **check_,
> +			  const char *one, ...)
>  {
> -	struct git_attr_check *check;
>  	int cnt;
>  	va_list params;
>  	const char *param;
> +	struct git_attr_check *check;
> +
> +	if (*check_)
> +		return;
> +
> +	attr_lock();
> +	if (*check_) {
> +		attr_unlock();
> +		return;
> +	}
> ...
>  	check = xcalloc(1,
> -			sizeof(*check) + cnt * sizeof(*(check->check)));
> +			sizeof(*check) + cnt * sizeof(*(check->attr)));
> ...
> +	*check_ = check;
> +	attr_unlock();

Sigh. DCLP, the Double Checked Locking Pattern. These days, it should be common knowledge among professionals that this naïve version _does_not_work_ [1]!

I suggest you go without it, then measure, and only *then* optimize if it is a bottleneck. Did I read "we do not expect much contention" somewhere?

[1] http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf C++ centric, but applies to C just as well

-- Hannes
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 16 in “[PATCHv2] attr: convert to new threadsafe API”
  1. Stefan BellerOct 11, 2016
  2. Junio C HamanoOct 12, 2016
  3. Stefan BellerOct 12, 2016
  4. Junio C HamanoOct 12, 2016
  5. Stefan BellerOct 12, 2016
  6. Junio C HamanoOct 12, 2016
  7. Junio C HamanoOct 12, 2016
  8. Johannes SixtOct 12, 2016
  9. Junio C HamanoOct 12, 2016
  10. Stefan BellerOct 12, 2016
  11. Junio C HamanoOct 12, 2016
  12. Jacob KellerOct 12, 2016
  13. Stefan BellerOct 12, 2016
  14. Junio C HamanoOct 12, 2016
  15. Stefan BellerOct 12, 2016
  16. Junio C HamanoOct 12, 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.