Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2007

Tip: Looking for answers? Try searching our database.

Semaphores and store-room problem.

Thread view: 
ppp - 15 Jan 2007 21:17 GMT
Hi, I think about solution of my exercise. Here it is:

There is product which contains three components: a, b and c. There are
3 processes (A, B and C) - each of them product one part (e.g. A create
one part a) and put it into store-room. There is also process M, which
takes one of each components and create product.
I have to do this using semaphores, but i wish to use least of them.
Maybe some of you have solution of this? I will be thankfull for any
help.
Knute Johnson - 16 Jan 2007 01:27 GMT
> Hi, I think about solution of my exercise. Here it is:
>
[quoted text clipped - 5 lines]
> Maybe some of you have solution of this? I will be thankfull for any
> help.

I assume that you want to wait until you have (a,b,c) finishe before you
call M?

In that case the three parts (a,b,c) should each have a semaphore with
one permit that the part holds until it is complete.  When it is
complete then it releases the semaphore and M can acquire all three
before making the product.

Signature

Knute Johnson
email s/nospam/knute/

ppp - 16 Jan 2007 10:02 GMT
Knute Johnson napisal(a):
> > Hi, I think about solution of my exercise. Here it is:
> >
[quoted text clipped - 18 lines]
> Knute Johnson
> email s/nospam/knute/

Yes, but buffer size is limited e.g. 10, and I don't know how to
prevent stack a b c (a must wait when a=8, b=1, and c=0)
Knute Johnson - 16 Jan 2007 17:35 GMT
> Knute Johnson napisal(a):
>>> Hi, I think about solution of my exercise. Here it is:
[quoted text clipped - 22 lines]
> Yes, but buffer size is limited e.g. 10, and I don't know how to
> prevent stack a b c (a must wait when a=8, b=1, and c=0)

You need to look at Semaphore in the documentation, that's the first
thing.  I don't really know how your program is going to work because
you haven't told us.  From what little I know about what you want to do,
I would use a different Semaphore for each type of part.  If the whole
takes 8 a parts then you will need 8 permits in the Semaphore.

Logic flow:

A acquires permits, starts building a parts, when each part is complete
it releases a permit.

B does same

C does same

M waits until it can acquire all 3 semaphores then makes product and
when it is done it releases all semaphores

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.