+ 1

What all concurency technic is best

 print server can accept jobs from Network and USB. The server can accept multiple jobs but can process only one at a time. Assume each job comes with an input which informs us the amount of time it takes to finish the job. Also, the jobs that come via USB get a high priority.   Above statement is best implemented with which comcurency technic ?

31st May 2022, 12:00 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 2
In this case I would use a queue for NET and a queue for USB. In the server I would decide which queue to read from. I coded a simple example. In this example you do not event need Mutex or Condition Variable to archieve this concurency. https://code.sololearn.com/ce4g5s2mL2mF
11th Jun 2022, 2:52 PM
Victor Cortes
Victor Cortes - avatar
+ 2
Mutex is not necessary in cases that you are using a thread-safe container to manage requests between threads, but no problem if you use it correctly. The best way to make concurency task is simply avoid them to occur by using queues, thread-safe containers and atomic variables. That makes a cleaner, stable code. Mutex takes the semaphore responsability to the programmer, that can surely increase the chance to cause deadlocks and runtime errors. In most cases you won't need to control that manually.
11th Jun 2022, 10:11 PM
Victor Cortes
Victor Cortes - avatar
+ 1
Thanks 😊.. I am sorry but concurrency without mutex in thread seems impossible to me.... I might be wrong Also there can be a print request even when print is in progress Plus I would go with priority queue with usb job has high priority to take care of the preference What my query is on the mutex choice or semaphore if we choose thread Is thread necessary or multiple process is best here in this case? Having said this , many thanks for sharing your view and thoughts
11th Jun 2022, 5:01 PM
Ketan Lalcheta
Ketan Lalcheta - avatar