

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Operating Systems; Subject: Engineering Computer Science; University: University of California - Davis; Term: Fall 2008;
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


y = 2 ; p a r b e g i n x = y ∗ 2 ; y = 6 ; parend ;
t y p e d e f monitor { / ∗ s c o u n t i s t h e i n t e g e r v a l u e o f t h e semaphore ; i f t h i s i s t o o b i g and t h e p r o c e s s t r i e s t o up i t , t h e p r o c e s s w i l l b l o c k on t o o b i g ; s i m i l a r l y , i f t h e v a l u e i s t o o s m a l l and t h e p r o c e s s t r i e s t o down i t , t h e p r o c e s s w i l l b l o c k on t o o s m a l l. ∗ / i n t s c o u n t = 0 ; c o n d i t i o n t o o b i g , t o o s m a l l ;
/ ∗ s t r a i g h f o r w a r d i m p l e m e n t a t i o n o f up ∗ / v o i d e n t r y up ( v o i d ) { / ∗ i f t o o b i g , w a i t u n t i l ok ∗ / w h i l e ( s c o u n t >= SMAX) t o o b i g. w a i t ; / ∗ i n c r e m e n t and n o t i f y someone w a i t i n g f o r t h e semaphore t o be n o n z e r o t h a t i t i s ∗ /
s c o u n t += 1 ; t o o s m a l l. s i g n a l ; }
/ ∗ s t r a i g h f o r w a r d i m p l e m e n t a t i o n o f down ∗ / v o i d e n t r y down ( v o i d ) ; b e g i n / ∗ i f t o o s m a l l , w a i t u n t i l ok ∗ / w h i l e ( s c o u n t <= 0 ) t o o s m a l l. w a i t ; / ∗ d e c r e m e n t and n o t i f y someone w a i t i n g f o r t h e semaphore t o be l e s s t h a n SMAX t h a t i t i s ∗ / s c o u n t −= 1 ; t o o b i g. s i g n a l ; } b o u n d e d s e m a p h o r e ;