Skip to content

Commit 0f4ca21

Browse files
committed
rt: Delete schedulers immediately upon release
This will be needed once we support dynamically changing schedulers.
1 parent bde9385 commit 0f4ca21

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/rt/rust_kernel.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ rust_kernel::rust_kernel(rust_srv *srv, size_t num_threads) :
2121
live_schedulers = 1;
2222
}
2323

24-
rust_kernel::~rust_kernel() {
25-
delete sched;
26-
}
27-
2824
void
2925
rust_kernel::log(uint32_t level, char const *fmt, ...) {
3026
char buf[BUF_BYTES];
@@ -83,6 +79,7 @@ void
8379
rust_kernel::release_scheduler() {
8480
I(this, !sched_lock.lock_held_by_current_thread());
8581
scoped_lock with(sched_lock);
82+
delete sched;
8683
--live_schedulers;
8784
if (live_schedulers == 0) {
8885
// We're all done. Tell the main thread to continue

src/rt/rust_kernel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class rust_kernel {
4747
struct rust_env *env;
4848

4949
rust_kernel(rust_srv *srv, size_t num_threads);
50-
~rust_kernel();
5150

5251
void log(uint32_t level, char const *fmt, ...);
5352
void fatal(char const *fmt, ...);

src/rt/rust_scheduler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ rust_scheduler::destroy_task_threads() {
5656
void
5757
rust_scheduler::start_task_threads()
5858
{
59+
// Copy num_threads because it's possible for the last thread
60+
// to terminate and have the kernel delete us before we
61+
// hit the last check against num_threads, in which case
62+
// we would be accessing invalid memory.
63+
uintptr_t num_threads = this->num_threads;
5964
for(size_t i = 0; i < num_threads; ++i) {
6065
rust_task_thread *thread = threads[i];
6166
thread->start();

0 commit comments

Comments
 (0)