CSC 4700 Chapter : HW3 CH8

7 views8 pages
15 Mar 2019
School
Course
Professor

Document Summary

Blake montalbano: if one thread has a read lock it is very likely that there are multiple threads with the read lock also. If it tries to start a write operation many threads will have read the wrong information and the program might not run correctly. To let this happen there would have to be a way to stop giving locks to read operations and once all but the thread wanting the write lock. Then it could perform its writes while not causing any reading threads to make mistakes: 1. class savings{ long balance=0; Atomicboolean state = new atomicboolean(false); void lock() { while (state. getandset(true)) {} void unlock() { state. set(false); public void deposit(int k){ If (k<0) return; lock(); balance = balance + k; unlock(); public void withdraw(int k){ If (k<0) return; lock(); if(balance-k<0) return; balance = balance + k; unlock(); class savings{ long balance=0;

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents