Skip to content

Commit

Permalink
Added simple deadlock detection in the scheduler.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbebenita committed Aug 18, 2010
1 parent 2c1ec67 commit a4b8c74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/rt/rust_dom.cpp
Expand Up @@ -368,6 +368,31 @@ rust_dom::schedule_task() {
return NULL;
}

/**
* Checks for simple deadlocks.
*/
bool
rust_dom::is_deadlocked() {
if (_live_domains.size() != 1) {
// We cannot tell if we are deadlocked if other domains exists.
return false;
}

if (running_tasks.length() != 0) {
// We are making progress and therefore we are not deadlocked.
return false;
}

if (_incoming_message_queue.is_empty() && blocked_tasks.length() > 0) {
// We have no messages to process, no running tasks to schedule
// and some blocked tasks therefore we are likely in a deadlock.
log_state();
return true;
}

return false;
}

void
rust_dom::log_all_state() {
for (uint32_t i = 0; i < _live_domains.size(); i++) {
Expand Down Expand Up @@ -427,6 +452,8 @@ rust_dom::start_main_loop()
logptr("exit-task glue", root_crate->get_exit_task_glue());

while (n_live_tasks() > 0) {
A(this, is_deadlocked() == false, "deadlock");

drain_incoming_message_queue();

rust_task *scheduled_task = schedule_task();
Expand Down
1 change: 1 addition & 0 deletions src/rt/rust_dom.h
Expand Up @@ -88,6 +88,7 @@ struct rust_dom

void reap_dead_tasks();
rust_task *schedule_task();
bool is_deadlocked();
int start_main_loop();

void log_state();
Expand Down

0 comments on commit a4b8c74

Please sign in to comment.