This branch fixes a potential race condition and double free issue when using automatic differentiation and multi-threaded assembly.