I have two threads (in C) that execute the following instructions:
void Foo() {
// function running in thread 1
1| head = NULL;
2| tail = NULL;
}
and
void Bar() {
// function running in thread 2
1| mid = mid-next;
2| tail = tail->next;
3| head = head->next;
}
Now, my problem is related in the lock-free programming domain and it goes like this:
- Thread 1 performs (1) and goes to sleep
- Thread 2 performs (1) and (2) and goes to sleep
- Thread 1 wakes up and notices (via a CAS instruction) that tail variable has changed and it rolls back its changes (the (1) instruction) and wants to help by continuing the Thread 2 work (the 3rd instruction from Bar method)
My question is: can we somehow continue the Thread 2 work from Thread 1? [e.g. by changing somehow the instruction pointer or by any other means] We can modify or persist all kind of thread state info.