Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 改进内核任务调度机制提升稳定性 https://github.com/siyuan-note/siyuan/issues/7113

Liang Ding6d100464dd49
diff --git a/kernel/task/queue.go b/kernel/task/queue.go
index 850909c937..fc4c6226f9 100644
--- a/kernel/task/queue.go
+++ b/kernel/task/queue.go
@@ -29,7 +29,6 @@ var (
taskQueue []*Task
taskQueueStatus int
queueLock = sync.Mutex{}
- taskLock = sync.Mutex{}
)
const (
@@ -137,6 +136,8 @@ func StatusLoop() {
}
}
+var taskWaitGroup = sync.WaitGroup{}
+
func Loop() {
for {
time.Sleep(10 * time.Millisecond)
@@ -154,7 +155,9 @@ func Loop() {
break
}
- execTask(task)
+ taskWaitGroup.Add(1)
+ go execTask(task)
+ taskWaitGroup.Wait()
}
}
@@ -189,8 +192,6 @@ func popTask() (ret *Task) {
}
func execTask(task *Task) {
- taskLock.Lock()
- defer taskLock.Unlock()
defer logging.Recover()
args := make([]reflect.Value, len(task.Args))
@@ -201,5 +202,7 @@ func execTask(task *Task) {
args[i] = reflect.ValueOf(v)
}
}
+
task.Handler.Call(args)
+ taskWaitGroup.Done()
}