since delete is implemented using malloc's free(), it could be that free() takes a long time, so it would be worth it to allow other linked-list deletes to occur while free() is occuring. Also, if malloc is multithreaded, this allows us to take advantage of that.
This comment was marked helpful 0 times.
yetianx
@Q_Q: I think your optimization breaks exclusivity and sometimes it will release the lock before deleting, leading to a corrupted linked list.
This comment was marked helpful 0 times.
jinsikl
@yetianx I don't think so. By the time delete cur is called, the node pointed by cur is no longer in the list. So it's safe to release the lock before calling delete. Of course, we have to assume that delete is correctly implemented to handle concurrent execution by multiple threads (but that seems like a pretty safe assumption to make).
This comment was marked helpful 1 times.
traderyw
In certain cases when not too many threads are competing for resources, using a global lock data structure is faster than using a fine-grained lock data structure because a fine-grained lock data structure has more overhead.
A quick optimization that can be had here is to move the "unlock(list->lock);" above "delete cur;" in delete(), so that it looks like this:
since delete is implemented using malloc's free(), it could be that free() takes a long time, so it would be worth it to allow other linked-list deletes to occur while free() is occuring. Also, if malloc is multithreaded, this allows us to take advantage of that.
This comment was marked helpful 0 times.
@Q_Q: I think your optimization breaks exclusivity and sometimes it will release the lock before deleting, leading to a corrupted linked list.
This comment was marked helpful 0 times.
@yetianx I don't think so. By the time
delete cur
is called, the node pointed bycur
is no longer in the list. So it's safe to release the lock before callingdelete
. Of course, we have to assume thatdelete
is correctly implemented to handle concurrent execution by multiple threads (but that seems like a pretty safe assumption to make).This comment was marked helpful 1 times.
In certain cases when not too many threads are competing for resources, using a global lock data structure is faster than using a fine-grained lock data structure because a fine-grained lock data structure has more overhead.
This comment was marked helpful 0 times.