I didn\'t know much about sequence locks. Is it disregards the read result and t
ID: 3756186 • Letter: I
Question
I didn't know much about sequence locks. Is it disregards the read result and tries to re-read if it detects a change? What if the writer is half way through updating the information and the reader tries to parse this data? if the data is in a malformed state because it is only half updated it could cause the reader to parse bad information and crash? My guess is that this is only meant for every simple data like simple data buffers and not complicated data structures. Can anyone identify and pieces of code that use this?
Explanation / Answer
According to my knowledge this question can be answered in following way:
Suppose I have an elearning website which gives lectures consisting no. of classes. Here Main data structure is lectures and each lecture contain multiple classes having time slots in which student can attend the classes. So classes will be my branches and node will be my lecture.
Now I have following two conditions:
a.) If the number of students exceeds the critical value or predefined value then a new class and its slot is added but students can only attend that class once.
b.) If the student attends different class then he/she is logged out of the current class.
So following set of operations will be followed to create a data structure for the case mentioned above:
a.) Attend lecture
b.) Remove student
c.) Cancel class
d.) Cancel lecture
e.) Get details of no. of classes running and no. of students invloved
Now Sequence locks will be implemented for performing the tasks/operations mentioned above and these are discussed as follows:
a.) Coarse-Grained Locking : To manage large pool of clients requesting for the page and to save system from crashing, a new thread is created by operating system. Same way, a thread which wants to access a state which is shared is locked and then read or write operation is performed on it and then the lock is released. It is relatively very simple approach.
Limitation: If the there are multiple users accessing the same information/page then multiple threads will be created which will slow down the system and response time will increase. Here priority based threads can be created which can also classified as Lower priority thread and Higher priority thread.
b.) Fine-Grained Locking: When there are n no. of clients wants to access a particular page or very small information then the threads which are created to manage the processing time and load time will increase. To overcome this issue, multiple locks will be set in sequence to lock the specific part of data structure on which the current thread is operating.
Limitation: Concurrency problems occurs such as dead locks,live locks and lock convoy.
Please thumbs up/Upvote if the given answer addresses your doubts.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.