ChatGPT can help you get non trivial things done. In this case, I wanted to build something that didn’t have much of a precedent that ChatGPT could build on. However, ChatGPT does seem to have some logical abilities (by generating logical looking code). I used it as a second brain and dumped some responsibilities on it so that I could keep my head relatively clear. When building something as non-trivial as a lockfree data structure, there are many edge cases to consider. I went through a process where I pointed out cases to ChatGPT, sometimes suggesting opinionated fixes and giving it outright patches, and sometimes asking ChatGPT to point out these cases itself.
I think it helped because I didn’t have to consider all the cases myself. To go into some specifics of how lockfree structures are implemented, at the core of it is the compare-and-swap instruction. It takes a pointer, an expected current value, and a new value, and sets the value at location pointer to new value only if it is equal to the current value before the update is done. The whole operation is completed atomically, using a special hardware instruction that performs both the compare-and-swap in one CPU instruction.
When building a concurrent data structure, we must take into account how different interleavings of the data structure’s methods affect the correctness of our program. This is complicated. Seemingly trivial things such as computing the size of a data structure are not trivial, and accepted size algorithms that are shipped with libraries could have a negative return value with a particular interleaving with other methods.
That is exactly the problem that my PR focused on. It took me 5-8 hours of work to do that. The big range is because I was mid-travel and did it in short sprints. Now that I mention it, that is another advantage of programming with ChatGPT. I would have otherwise forgotten my chain of thought after a gap, but I had it both in my chats and queryable with English language :). I had read through the mentioned paper before though, and I think reading the paper and implementing it in one go would’ve taken longer. This is the pull request.
I used the GPT-4 model. I don’t think the stock ChatGPT model would’ve been useful in this case.