+ 11

[SOLVED] Thread priority problem

Dear fellow programmers Somebody knows why continues giving an arbitraire execution even setting higher priority to one thread respect to another? From PRO exercise found at https://www.sololearn.com/learning/2185/ Initial code: https://code.sololearn.com/cVKM7v9q4FR7/?ref=app My buggy code: https://code.sololearn.com/cOgK28o6QPIH/?ref=app

21st Jan 2021, 11:27 AM
David OrdĂĄs
David OrdĂĄs - avatar
5 Answers
+ 5
I answered this for Minho đŸ‡°đŸ‡· yesterday. See explanation in this code. https://code.sololearn.com/c9ckWvwXiXcZ/?ref=app
23rd Jan 2021, 1:57 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 5
Elizabeth Kelly Minho đŸ‡°đŸ‡· thanks! Its something that I supouse. I know that managing resources are blocking operations and depending on the time taken in resolve them, makes appearing arbitraire results. Let me think if I'm right... Maybe how to solve correctly (producer-consumer pattern) .... - JDK1+ shared mutex object calling method wait() in one thread and notify() in the other. - JDK5+ using concurrent/atomic pkg: Semaphore / Countdown Barrier, AtomicInteger... The extrange thing is that an official SoloLearn practice hints you to resolve it using thread priorities đŸ€”đŸ€”. So...Might be a buggy exercise 😂😂 ???
25th Jan 2021, 3:59 PM
David OrdĂĄs
David OrdĂĄs - avatar
+ 4
David Ordás if a producer / consumer solution is required, the recommendation is to use ‘synchronized’ methods for managing access to the shared resource. That is the current standard with JDK11 anyways.
25th Jan 2021, 10:19 PM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 2
Same problem https://www.sololearn.com/Discuss/2606071/?ref=app Threads depends on OS support and the scheduler in charge to orchetation takes the lastest word independiently of setted priority. Once look at this : https://www.sololearn.com/Discuss/2211828/?ref=app
25th Jan 2021, 4:56 PM
David OrdĂĄs
David OrdĂĄs - avatar
25th Jan 2021, 7:26 PM
David OrdĂĄs
David OrdĂĄs - avatar