Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/internal/task/task_threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ func CoroExit(next *Task) {
tinygo_task_exit()
}

// Yield yields the current thread to the OS scheduler.
func Yield() {
sched_yield()
}

// scanWaitGroup is used to wait on until all threads have finished the current state transition.
var scanWaitGroup waitGroup

Expand Down Expand Up @@ -372,6 +377,9 @@ func tinygo_task_send_gc_signal(threadID)
//export tinygo_task_current
func tinygo_task_current() unsafe.Pointer

//export sched_yield
func sched_yield() int32

func NumCPU() int {
return int(numCPU)
}
3 changes: 0 additions & 3 deletions src/runtime/runtime_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,6 @@ func signal_disable(s uint32) {
func signal_waitUntilIdle() {
// Wait until signal_recv has processed all signals.
for receivedSignals.Load() != 0 {
// TODO: this becomes a busy loop when using threads.
// We might want to pause until signal_recv has no more incoming signals
// to process.
Gosched()
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/scheduler_threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func scheduleTaskNoWake(t *task.Task) {
}

func Gosched() {
// Each goroutine runs in a thread, so there's not much we can do here.
// There is sched_yield but it's only really intended for realtime
Comment thread
davecheney marked this conversation as resolved.
// operation, so is probably best not to use.
// Each goroutine runs in a thread, so yield the thread to let other
// goroutines make progress.
task.Yield()
}

// NumCPU returns the number of logical CPUs usable by the current process.
Expand Down
Loading