1 /* Checks that recent_cpu and priorities are updated for blocked
4 The main thread sleeps for 25 seconds, spins for 5 seconds,
5 then releases a lock. The "block" thread spins for 20 seconds
6 then attempts to acquire the lock, which will block for 10
7 seconds (until the main thread releases it). If recent_cpu
8 decays properly while the "block" thread sleeps, then the
9 block thread should be immediately scheduled when the main
10 thread releases the lock. */
13 #include "tests/threads/tests.h"
14 #include "threads/init.h"
15 #include "threads/malloc.h"
16 #include "threads/synch.h"
17 #include "threads/thread.h"
18 #include "devices/timer.h"
20 static void block_thread (void *lock_);
23 test_mlfqs_block (void)
28 ASSERT (thread_mlfqs);
30 msg ("Main thread acquiring lock.");
34 msg ("Main thread creating block thread, sleeping 25 seconds...");
35 thread_create ("block", PRI_DEFAULT, block_thread, &lock);
36 timer_sleep (25 * TIMER_FREQ);
38 msg ("Main thread spinning for 5 seconds...");
39 start_time = timer_ticks ();
40 while (timer_elapsed (start_time) < 5 * TIMER_FREQ)
43 msg ("Main thread releasing lock.");
46 msg ("Block thread should have already acquired lock.");
50 block_thread (void *lock_)
52 struct lock *lock = lock_;
55 msg ("Block thread spinning for 20 seconds...");
56 start_time = timer_ticks ();
57 while (timer_elapsed (start_time) < 20 * TIMER_FREQ)
60 msg ("Block thread acquiring lock...");