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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:34+00:00 2026-06-17T12:33:34+00:00

Suppose I have threads t1,t2,t3……t10 and I need to access the printer and scanner,

  • 0

Suppose I have threads t1,t2,t3……t10 and I need to access the printer and scanner, order is first scan and then print using this threads so how do I ensure that t1,t2…t10(by multiple users) can access the scanner or printer without deadlock.

t1 finishes his job of scanning and waiting for printer and now t2 is doing job of printing the doc. So how do I ensure that t1 should not interrupt the job t2. now t2 finishes his job of printing same user wants to scan the another document but it is not released by t1. so deadlock between t1 and t2, t1 wants printer and t2 wants scanner but they already holding the other ones resource.

  • 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-17T12:33:34+00:00Added an answer on June 17, 2026 at 12:33 pm

    t1 finishes his job of scanning and waiting for printer and now t2 is doing job of printing the doc. So how do I ensure that t1 should not interrupt the job t2.

    A good way to implement such a mechanism is to use a queue, for example a thread safe BlockingQueue and have 2 consumer threads:

    • the Printer Thread that takes jobs from the printerQueue
    • the Scanner Thread that takes jobs from the scannerQueue

    Then your T0…T10 simply put jobs in one of the queues and wait (or not) for them to be executed when the Printer/Scanner is ready.

    By doing that you remove the need to lock on the client/producer side and let the consumer side (Printer and Scanner) to manage their jobs.

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

Sidebar

Related Questions

Suppose I have to spawn off 100 threads to access a HTTP resource. Since
Suppose we have a shared queue (implemented using an array), which two threads can
Suppose I have a program that initializes a global variable for use by threads,
Suppose I have two threads A and B , both running. Suddenly B decides
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;
Let us suppose I have 2 threads and a single global variable in a
Suppose you have an object which can be accesed by many threads. A critical
Suppose I have a function that tries to protect a global counter using this
Suppose I have two threads. On one thread, I'm performing a sequence of jobs.
Suppose I have singleton class that acts as a data cache. Multiple threads will

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.