All MicroEvals
You are an expert Systems Engineer and Concurrency Specialis...
Create MicroEval

You are an expert Systems Engineer and Concurrency Specialis...

Prompt

You are an expert Systems Engineer and Concurrency Specialist. I need you to implement a highly robust, thread-safe, priority-based Task Scheduler in Python (using only the standard library, no third-party packages). The scheduler must satisfy the following strict requirements: 1. Core Mechanics: - Supports tasks with different priorities (0 is highest, 10 is lowest). - Supports setting a "timeout" for each task. If a task waits in the queue for longer than its timeout before execution begins, it must be discarded (and its rejection must be logged). - Uses a thread pool for execution. 2. Advanced Constraints (The Trap): - Starvation Prevention: To prevent low-priority tasks from starving, implement an "aging" mechanism. Every 5 seconds a task waits in the queue, its priority number should dynamically decrease by 1 (e.g., from 10 to 9, making it more important). - Deadlock Avoidance: Multiple workers will pull tasks from the queue. You must ensure there are no race conditions regarding the dynamic priority updates and the timeout checks. - Graceful Shutdown: Implement a `shutdown()` method that stops accepting new tasks, waits for currently running tasks to finish, and safely discards all queued tasks. 3. Deliverables: - Provide the complete, runnable Python code. - Provide a highly concurrent unit test (using `threading` or `concurrent.futures`) that simulates 50 simultaneous tasks with mixed priorities, some of which will inevitably timeout, to prove your scheduler handles race conditions correctly without deadlocking. - Explain the exact time complexity of `push` and `pop` operations in your implementation and justify your choice of data structure.

Drag to resize
Drag to resize

Response not available

Drag to resize
Drag to resize
Drag to resize