Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:31:55+00:00 2026-05-31T04:31:55+00:00

I’m trying to implement the pseudo solution below in java as part of an

  • 0

I’m trying to implement the pseudo solution below in java as part of an assignment. The pseudo is for a Readers Preference program, specifically the reader process itself. There is an accompanying writer process, but to keep things spartan I didn’t bother pasting it.

Process Reader[i=1 to M] {
  while (true) {
    /* Implementing <await (nw == 0) nr = nr+1;> */
    P(e);
    if (nw > 0) {dr = dr+1; V(e); P(r);}
    nr = nr + 1;
    if (dr > 0) {dr = dr-1; V(r);}
    else V(e);
    read the database;
    /* Implementing <nr = nr-1;> */
    P(e);
    nr = nr - 1;
    if (nr == 0 and dw > 0) {dw = dw-1; V(w);}
    else V(e);
  }
}

Originally I assumed that the line:

/* Implementing <await (nw == 0) nr = nr+1;> */

Was some kind of commenting on what was occurring, but having just re-read it I think it’s supposed to be an if statement to control the P(e) locking semaphore. Below is what I’ve implemented in my code based on the above assumption.

if (nw == 0) {
  nr = nr++;
  try {
    e.acquire();//P(e)
  } catch (InterruptedException e) {
  }
}//end if

The output from the rest of the code has been a bit of a mess, but it seems to work. I used delays with a thread.sleep in order to make the output to console more readable and again it seemed ok, though I was wary about using delays as that seemed quite likely to interfere with the results, since I was giving the writer processes a longer delay. In theory though, the locking system should be sound and the delays should just make the output to console more readable.

So, am I correct to use the if statement above?

Can you give me any tips on outputting data to the console to prove it works as it should (readers preference/writers preference)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:31:57+00:00Added an answer on May 31, 2026 at 4:31 am

    The line

    /* Implementing <await (nw == 0) nr = nr+1;> */
    

    is an atomic process, the code below carries that out atomically.

    If anyone was interested about the other question, just add print statements under the acquire/release.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.