Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does reading involve any locking in multithreaded applications?

Suppose I have a data structure S in memory. S is complex, say a tree or a graph. I have two threads travelling through S, and they may hit and try to read the same address at the same time. My question is: is there any kind of implicit locking at this point such that contention between the threads arises? If it is of value, I'm using C, pthreads on a regular SMP machine.

like image 902
Dervin Thunk Avatar asked Apr 07 '26 06:04

Dervin Thunk


1 Answers

No. There is no need for locking with read-only operations.

There would only be locking if you explicitly implement it. This would usually be done when there's a chance of another thread modifying (writing) the structure at the same time.

like image 198
Brian Roach Avatar answered Apr 09 '26 20:04

Brian Roach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!