美文网首页
[崩溃日志]Simultaneous accesses to 0

[崩溃日志]Simultaneous accesses to 0

作者: 尼达先森 | 来源:发表于2019-06-21 11:20 被阅读0次

今天遇到原本没问题的项目在播放音频后报错:

Simultaneous accesses to 0x28261ebd0, but modification requires exclusive access. Previous access (a

屏幕快照 2019-06-21 上午10.42.03.png

原因是结构体需要同时进行读写操作导致线程不安全

代码如下:

sound.requestSound(success: { (url) in
     self.startPlayRecord(path: url)
     sound.isPlaying = true          // 1
     tempChat.type = .sound(sound)   // 2
}, failure: {
      ChatManager.shared.chats[index] = tempChat
})

修改后

var mySound = sound
var myTempChat = tempChat
sound.requestSound(success: { (url) in
       self.startPlayRecord(path: url)
       mySound.isPlaying = true          // 1
       myTempChat.type = .sound(mySound)   // 2
 }, failure: {
        ChatManager.shared.chats[index] = myTempChat
})

相关文章

网友评论

      本文标题:[崩溃日志]Simultaneous accesses to 0

      本文链接:https://www.haomeiwen.com/subject/sjtyqctx.html