• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Deadlock K&B program

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
K&B book deadlock program is below



it says "Assume that read() is started by one thread and write() is started by another thread.if there are two different thrads thay may read and write independently,there is a risk of deadlock at line 8 or 16.

I tried to execute the above program with two thread.but i am having trouble how to start two new threads calling read() and write() methods.please help me on this.

my program is
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the calls to read and write in run method.


To be doubly sure have a sleep method between the synchronizations

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answer swarna.


so without creating an anonymous inner class,i don't think this program running in two different threads calling read() and write() method is possible.Am i correct?
 
swarna dasa
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Objective - one thread needs to run read and the other write.
This can be done by the following:-
1) Anonymous class
2) Non static Inner class
3) Static Nested class
4) Create 2 subclasses A1 and A2 extending Chapter9, one calling read and the other calling write in run method.

These are the only ways i think we can run the required scenario.
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic