I have to post a simplified version of the code because it\'s quite big otherwise.
I have two threads running the same code in parallel, we can call them A and B.