C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-03-2003, 08:01 PM   #1
Registered User
 
Join Date: Apr 2003
Posts: 3
Semaphore problem

Got this problem straight from the book "Operating Systems" 2nd edition by Gary Nutt chapter 8 #13 and I'm having a hard time of it. Sorry for the wording it is the book. Need help.

I'm taking an Operating Systems class and stuck on a problem with Semaphores.
Here it is:
Suppose a machine's instruction set includes an instruction named swap that operates as follows (as an indivisible instruction):

swap(boolean *a, boolean *b)
{
boolean t;
t = *a;
*a = *b;
*b = t;
}

Show how swap can be used to implement the p and v operations.
LeeMan101 is offline   Reply With Quote
Old 04-03-2003, 09:34 PM   #2
Registered User
 
Codeplug's Avatar
 
Join Date: Mar 2003
Posts: 3,903
You mean swap() is an "atomic" instruction - meaning it cannot be interrupted and will always execute to completion without a context-switch.

To reword the problem statement: If you have multiple threads calling p() and v(), how do you synchronize within the p() and v() implementation using only swap()? The fact that swap() takes a boolean is a big hint.

gg
Codeplug is offline   Reply With Quote
Old 04-04-2003, 08:13 AM   #3
Registered User
 
Join Date: Apr 2003
Posts: 3
Thanks for the response and the hint. The book we are using is poorly written. They are going to get a new book next semester. In the meantime my class is the guinea pig.
LeeMan101 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
cross platform semaphore problem jet-plane C Programming 0 05-24-2008 01:59 PM
Memory problem with Borland C 3.1 AZ1699 C Programming 16 11-16-2007 11:22 AM
Someone having same problem with Code Block? ofayto C++ Programming 1 07-12-2007 08:38 AM
A question related to strcmp meili100 C++ Programming 6 07-07-2007 02:51 PM
WS_POPUP, continuation of old problem blurrymadness Windows Programming 1 04-20-2007 06:54 PM


All times are GMT -6. The time now is 05:39 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22