From: qydysky Date: Thu, 7 Sep 2023 01:02:46 +0000 (+0800) Subject: Fix data race X-Git-Tag: v0.11.2~16 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=e248de4834b096ee45594484d413a1174d0641f1;p=bili_danmu%2F.git Fix data race --- diff --git a/Reply/stream.go b/Reply/stream.go index 2cf078b..97200db 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -1195,8 +1195,11 @@ func (t *M4SStream) Start() bool { t.log.L(`I: `, `初始化录制(`+strconv.Itoa(t.common.Roomid)+`)`) defer t.log.L(`I: `, `结束录制(`+strconv.Itoa(t.common.Roomid)+`)`) - defer t.exitSign.Done() - defer t.Status.Done() + defer func() { + // use anonymous func avoid data race and unexpect sign wait + t.Status.Done() + t.exitSign.Done() + }() // 初始化请求池 t.reqPool = t.common.ReqPool diff --git a/bili_danmu.go b/bili_danmu.go index 073d650..3823438 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -129,7 +129,7 @@ func Start() { defer cancelfunc() } - for exit_sign := true; exit_sign; { + for exitSign := false; !exitSign; { if c.C.Roomid == 0 { fmt.Println("回车查看指令") ctx, cancel := context.WithCancel(context.Background()) @@ -137,7 +137,7 @@ func Start() { select { case <-c: case <-interrupt_chan: - exit_sign = false + exitSign = true } cancel1() cancel() @@ -145,7 +145,7 @@ func Start() { fmt.Print("房间号: ", strconv.Itoa(c.C.Roomid), "\n") } - if !exit_sign { + if exitSign { break } @@ -297,7 +297,7 @@ func Start() { var cancelfunc = c.C.Danmu_Main_mq.Pull_tag(msgq.FuncMap{ `interrupt`: func(_ any) (disable bool) { exitloop = true - exit_sign = false + exitSign = true ws_c.Close() danmulog.L(`I: `, "停止,等待服务器断开连接") reply.StreamOStop(-1) //停止录制