Re: Freeing struct lock_file?
- From
David Turner <dturner@twopensource.com>
- Date
- Apr 4, 2015, 00:24 UTC
- Message-ID
- <1428107083.31333.11.camel@ubuntu>
- In-Reply-To
- <xmqqfv8gg9bp.fsf@gitster.dls.corp.google.com>
On Fri, 2015-04-03 at 15:01 -0700, Junio C Hamano wrote:
Show 10 quoted lines
> David Turner <dturner@twopensource.com> writes: > > > Why is it impossible to free struct lock_files? I understand that they > > become part of a linked list, and that there's an atexit handler that > > goes over that list. But couldn't we just remove them from the linked > > list and then free them? > > I suspect that the code is worried about getting a signal, while it > is manipulating the linked list, and then cause the atexit handler > to walk a list that is in a broken state.
This is technically possible, but practically unlikely: aligned pointer-sized writes are atomic on very nearly every processor, and that is all that is required to remove an item from a linked list safely in this case (though not, of course, in the general multi-threaded case).
But I can see why git wouldn't want to depend on that behavior. C11 has a way to do this safely, but AIUI, git doesn't want to move to C99 let alone C11. So I guess this will just have to remain the way it is.