← 返回 linkedin 的题目列表Concurrent Queue with Space Limitation
类型:online_judge
Implement a thread-safe queue with a fixed maximum space limitation. You need to implement the following methods:
enqueue(item): Add an element to the queue. If the queue is full, the thread should wait until space is available.
dequeue(): Remove and return an element from the queue. If the queue is empty, the thread should wait until an element is available.
Requirements:
Use locks to ensure thread-safe operations.
Design should support concurrent operations in a multithreaded environment.
Provide at least five unit test cases to verify the correctness of the implementation, including edge cases.
Input: No specific input format required, just implement the class and methods.
Output: Each method should return the result of its specified functionality. For the enqueue method, no return value is needed. For the dequeue method, it should return the element that was removed.