Closed TaixiangLu closed 8 months ago
demo e := &MyEvent{customData: "hello"} e.SetName("e1") event.AddEvent(e) 这里提示 fatal error: concurrent map writes 原因是 event.AddEvent方法里线程不安全的操作了map,这里为何不加上锁做成线程安全的呢?
me too
AddEvent 是用于注册一些预定义的事件对象,这里不需要加锁呀 就跟http server注册路由一样,应该在项目启动时就注册好了。
不会运行中临时添加,这种临时添加的没必要注册为event了(临时添加 说明信息一直在变化,注册上去浪费且没意义了),直接使用临时参数触发事件就行。
啥也不是,都报错了。至少不健壮吧
v1.1.2 开始 addEvent 已经加锁了。
v1.1.2
addEvent
demo e := &MyEvent{customData: "hello"} e.SetName("e1") event.AddEvent(e) 这里提示 fatal error: concurrent map writes 原因是 event.AddEvent方法里线程不安全的操作了map,这里为何不加上锁做成线程安全的呢?