79196689

Date: 2024-11-17 07:31:47
Score: 1
Natty:
Report link

The compiler error is not giving too much information here. With your code, imagine self.work being called parallels, there for, variable hello will have 2 write access from 2 different threads in a same time which cause data races as the error indicates. Using MainActor from your answer helps you eliminate possible of data races because now there only be one write/read access for Helloworld variables at one time thanks for Actor mechanism of protecting share mutable state.

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Has code block (-0.5):
  • Single line (0.5):
  • Low reputation (0.5):
Posted by: duckSern1108