awagh1
BAN USERFunc() might have called CalledFunc() again recursively. Which caused a case for need of re-entrant lock. So in this case same thread is waiting for the lock which was already acquired by it and hence deadlock.
So using re-entrant protection lock might help if that's the issue.
This is similar to typical producer consumer problem except a small difference. We don't need to block writing while reading and vice-versa. Here is pseudo code:-
mutex m1
mutex m2
semaphore sem_full = SIZE_Q
semaphore sem_empty = 0
Read()
{
wait(sem_empty)
m1.lock()
//Do read operation of first element from Q
m1.unlock()
post(sem_full)
}
Write()
{
wait(sem_full)
m2.lock()
// Do write operation to write at back
m2.unlcok()
post(sem_empty)
}
Serialize:
- awagh1 March 29, 2016Do DFS while doing so maintain map table so that key is node and value list of immediate children
Desrialize:
Read each key in map table create node and recursively create it's children