Advertisement
Guest User

thread_init

a guest
Jan 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. /* Initializes the threading system by transforming the code
  2.    that's currently running into a thread.  This can't work in
  3.    general and it is possible in this case only because loader.S
  4.    was careful to put the bottom of the stack at a page boundary.
  5.  
  6.    Also initializes the run queue and the tid lock.
  7.  
  8.    After calling this function, be sure to initialize the page
  9.    allocator before trying to create any threads with
  10.    thread_create().
  11.  
  12.    It is not safe to call thread_current() until this function
  13.    finishes. */
  14. void
  15. thread_init(void) {
  16.     ASSERT (intr_get_level() == INTR_OFF);
  17.  
  18.     lock_init(&tid_lock);
  19.     list_init(&ready_list);
  20.     list_init(&all_list);
  21.     list_init(&sleep_list);
  22.     sema_init(&sleep_semaphore, 1);
  23.  
  24.     /* Set up a thread structure for the running thread. */
  25.     initial_thread = running_thread();
  26.     init_thread(initial_thread, "main", PRI_DEFAULT);
  27.     initial_thread->status = THREAD_RUNNING;
  28.     initial_thread->tid = allocate_tid();
  29.  
  30.     /* Initializing "load_avg_const1", "load_avg_const2", then "load_avg" of the system for MLFQ Scheduler */
  31.     load_avg_const1 = divide_int(convert_to_fixed(ALPHA), BETA);
  32.     load_avg_const2 = divide_int(convert_to_fixed(ZETA), BETA);
  33.     load_avg = convert_to_fixed(0);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement