hello everyone...probably this is my first post here so CMIIW...btw currently I have a problem regarding locking implementation on sorted singly-linked list. So far I am only able to implement coarse-locking method with mutex, and the code is as follows :
Note that access to first also needs to be protected. This was an issue already with your previous code.
It's not only the write accesses that need to be protected. If a value can be modified then you also need to protect the reads so that you don't end up in a situation where one thread modifies the value while other threads are reading it.
Between the assignment and the lock, an asynchronous process could have removed the node from the list entirely.
Yes - but isn't it worse than that as the value of first could change after it's value is obtained but before it is assigned to succ as the assignment is not atomic. Don't you first need a lock on first and then assign to succ?