Fix syn-read, syn-write, and always free elements from donors_list

This commit is contained in:
2024-11-12 21:30:23 +00:00
parent ca9d23edf9
commit dd979f34c8
3 changed files with 16 additions and 6 deletions

View File

@@ -212,6 +212,7 @@ donate_priority (struct thread *donee) {
ASSERT (intr_get_level () == INTR_OFF);
struct thread *donor = thread_current ();
list_remove (&donor->donor_elem);
list_push_back (&donee->donors_list, &donor->donor_elem);
while (donee != NULL)
@@ -342,7 +343,6 @@ lock_release (struct lock *lock)
released, transfer the remaining orphaned donors to its donor list. */
if (max_donor != NULL)
{
list_remove (&max_donor->donor_elem);
while (!list_empty (&orphan_list))
list_push_back (&max_donor->donors_list, list_pop_front (&orphan_list));
}

View File

@@ -373,7 +373,9 @@ thread_exit (void)
and schedule another process. That process will destroy us
when it calls thread_schedule_tail(). */
intr_disable ();
list_remove (&thread_current()->allelem);
struct thread *t = thread_current ();
list_remove (&t->allelem);
list_remove (&t->donor_elem);
thread_current ()->status = THREAD_DYING;
schedule ();
NOT_REACHED ();
@@ -679,6 +681,7 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
t->base_priority
= thread_mlfqs ? calculate_bsd_priority (recent_cpu, nice) : priority;
list_init (&t->donors_list);
list_push_back (&t->donors_list, &t->donor_elem);
t->waiting_lock = NULL;
t->nice = nice;

View File

@@ -133,11 +133,10 @@ start_process (void *proc_start_data)
/* Prevent writing to the file being executed. */
struct file *exec_file = filesys_open (data->file_name);
thread_current ()->exec_file = exec_file;
file_deny_write(exec_file);
file_deny_write (exec_file);
lock_release (&filesys_lock);
success = load (data->file_name, &if_.eip, &if_.esp);
lock_release (&filesys_lock);
/* If load failed, quit. */
if (!success)
@@ -326,7 +325,13 @@ process_exit (void)
uint32_t *pd;
printf ("%s: exit(%d)\n", cur->name, cur->exit_status);
file_close (cur->exec_file);
if (cur->exec_file != NULL)
{
lock_acquire (&filesys_lock);
file_allow_write (cur->exec_file);
file_close (cur->exec_file);
lock_release (&filesys_lock);
}
/* Update process result. */
if (cur->result != NULL)
@@ -486,6 +491,7 @@ load (const char *file_name, void (**eip) (void), void **esp)
off_t file_ofs;
bool success = false;
int i;
lock_acquire (&filesys_lock);
/* Allocate and activate page directory. */
t->pagedir = pagedir_create ();
@@ -585,6 +591,7 @@ load (const char *file_name, void (**eip) (void), void **esp)
done:
/* We arrive here whether the load is successful or not. */
file_close (file);
lock_release (&filesys_lock);
return success;
}