Dr. Rob Edwards from San Diego State University describes how the compare and swap algorithm works. This is widely used in counting kmers since it provides a lockfree hashing method.