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 8668153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:08:36+00:00 2026-06-12T18:08:36+00:00

I am currently studying the multithreaded programming and I am having a hard time

  • 0

I am currently studying the multithreaded programming and I am having a hard time mastering shared resources between threads.

I have two shared resources, time and alarm

I have three threads, one keeps updating time every second, one monitors time against alarm and finally one changes time and alarm at user request.

this is to be done using mutual exclusion semaphore, I have a simple setup described below:

  1. Main thread, program begins here, hosts time and alarm common variables and instantiates sub threads.
  2. Tick sub-thread, sleeps every 1000ms, then modifies Mother thread’s time variable
  3. UserInput sub-thread, is blocked until a user input is caught, and modifies either time or alarm in Main thread.
  4. Alarm sub-thread, sleeps every 1000ms, goes off when alarm == time

The Main thread keeps a mutex for each resource so only one thread can access it at a time.

Is such design reasonable or am I just over complicating things?

  • 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-12T18:08:38+00:00Added an answer on June 12, 2026 at 6:08 pm

    My first comment would be on the language you use, which may be an indication of some misunderstanding on your part. A thread doesn’t own any variables; this may mean that you have declared several custom subclasses of Thread. If that is so, this would not be an advisable approach. Note that Thread is just the name of a class, it is not the actual thread—exactly the same way as File is not a file. You haven’t posted any code so I must resort to guesswork, but if what I describe is true then you should redesign. Use plain classes (that don’t subclass anything) and instantiate Thread with a Runnable.

    Second, it is not very clear what you imply by “mutex” as this is not a term defined by the Java Language Specification. If you mean something from the java.util.concurrent package, such as Semaphore, this would be overkill; if you mean just plain Java Object instances that you use as locks, that would be a simple and straightforward approach. Note, however, that you don’t really need any locking at all: volatile variables would be enough, or, at most, AtomicLongs (or whatever type you use) for the two timestamp values, so you can update them atomically.

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

Sidebar

Related Questions

I'm currently studying socket programming, i'm working on creating an application to use my
I am currently studying for an exam I'll have on x86 assembly. I didn't
I am currently studying recursion in school, and I have trouble thinking about methods
I'm currently studying the book Accelerated C++ (Koening/Moo) and I'm having trouble with one
Hi i am currently studying sql and I have 2 one to many tables
I'm currently self-studying C# in my free time and thought of a little project
currently i'm studying MySQL, sorry for my newbie question. Here my question I have
Currently studying bitwise arithmetic. It's really easy, because I have some CS background. But
I'm currently studying for an exam (which is in two days) for computer vision
I'm currently studying WordPress and want to create a custom Post Type and have

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.