'Throw exception if another thread is still holding the lock?
I'm working on a multithreading program for school. It basically just hands off a string from one thread to another. Multiple threads are operating on a single instance of a class. They call methods like pass, receive, etc. The passing thread will block until a receiver comes(or timeout), and a receiver will block until a passer comes... Its a basic exercise in coordinating threads. One of the tests I'm really struggling with and it's called lock hog. Lets say one of the threads calls receive and the pass is complete, but the thread doesn't let go of the lock. Apparently what's supposed to happen is that the next thread that comes in should throw an illegal state exception, but I can't figure out how this is done. Is there a way to let a thread know that another thread is still holding the lock? Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
