I was trying to acheive a flow pattern similar to this:
threadA { while (1) {
mutB.lock
-work-
mutA.lock if (worktodo) { mutB.unlock } else { haveLocked = 1 } mutA.unlock } }
threadB { while (1) {
-work-
mutA.lock if (worktodo && isLocked) { mutB.unlock isLocked = 0 } mutA.unlock
} }threadA {
mutB.lock
-work-
mutA.lock if (worktodo) mutB.unlock mutA.unlock
}
threadB {
-work-
mutA.lock if (worktodo && mut.isLocked) mutB.unlock mutA.unlock
}
However, the second time that threadA tried to lock mutB, it just said "done" and let it go.
I assume that this was a safety built in to try to prevent users from creating deadlock, but as you see from my flow pattern, this is my intent.
How can I do this
Visual Studio Express Editions34
|