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

  • Home
  • SEARCH
  • 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 8852377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:23:08+00:00 2026-06-14T13:23:08+00:00

I want to write a program where two separate threads run two objects and

  • 0

I want to write a program where two separate threads run two objects and one thread waits to execute its code till it is signalled by the other.

Now to do this I want to use the Condition interface.

I am unable to figure out where to declare the lock and condition variables in my code such that both classes have access to it.

What I want to ask is, how do threads share the lock and condition variables so that it is ensured that they are signalling and waiting on the same condition.

  • 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-06-14T13:23:09+00:00Added an answer on June 14, 2026 at 1:23 pm

    The threads will have to have some sort of connection for this to work. If thread 1 has a reference to thread 2, the lock and condition variables may be in thread 2 and vice versa.

    If not, the variables will have to be in a separate class which both threads have access to. So, you’ll have to pass the same instance of that class to both threads, so that instance becomes a shared resource. Following example assumes you have classes Thread1 and Thread2 that extends Thread with a constructor taking SharedResource as an argument:

    SharedResource sr = new SharedResource();
    Thread1 t1 = new Thread1(sr);
    Thread2 t2 = new Thread2(sr);
    t1.start();
    t2.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write two program(.h and .cpp) with below code and use .h
suppose we have two numbers i want write program which print common bits subsequent
I write two program one is to takeoutAllButLast , other is takeoutSecondLast. I initially
I want to write a program in Prolog that confirms if a b-tree of
I want to write a program to contact a PHP script online, and show
I want to write a program which replaces each specific letter by text according
I want to write a program that automatically downloads all the csv files on
I want to write a program (preferably in java) that will parse and analyze
I want to write a program that would take a string, let's say Fox
I want to write a program to find the n-th smallest element without using

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.