![]() ![]() Here you can find the source code to the Java implementation as well as txt files, I created.Īs mentioned above, it is required to use any of the synchronization service providers, therefore I used Java Semaphores which served as a Mutex.Developing threaded software is always a challenge. Writer thread locking and modifying all the copies at once. Balance in the number of reader threads accessing files.Ħ. Single writer thread which tries to access the file at random periods.ĥ. ![]() Indefinite amount of reader threads spawning at random.ģ. Use any of the kernel resources that provide synchronization services: Semaphores, Mutexes, Monitors.Ģ. To simulate this problem, I decided to point out some bulletpoints that i would stick to:ġ. Now, coming up to the implementation details. That is, whenever a reader thread is trying to access the file, it will be forwarded to one of the 3 copies. Therefore, in order to simulate the problem and implement the solution I decided to use a general txt file, even 3 txt files ( the copies of the same file), in order to keep the balance with the minimal difference of the number of reader threads, trying to access each file. For that purpose, I can give the writer thread a so called preference that whenever a writer has an intention to access the database or any other file, the readers should wait for the writer thread to finish the modification. In the following code snippet, I tried to improve the default implementation of the reader/writer problem.Ĭonsidering the vast amount of reader threads, there is a lower possibility of writer thread to acquire the desired lock ( let’s assume it to be a DB lock). ![]() ![]() Reader/Writer Problem with Writer Preference. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |