davidevincenzi / DataLayer

1 stars 0 forks source link

Thread safety #1

Open davidevincenzi opened 5 years ago

davidevincenzi commented 5 years ago

@nfgrilo @aleksanderk I added the User entity and its relationship with the Event. About thread safety, do you have an example where this may be an issue?

aleksanderk commented 5 years ago

@davidevincenzi @nfgrilo I added two buttons that demonstrate a possible crash on master branch. Also created a new branch "data_layer_with_structs" for the approach with structs.

nfgrilo commented 5 years ago

That's great - I plan to work on this tomorrow. I have some ideas, but need to work them out, eventually coming with something hybrid between these two...

davidevincenzi commented 5 years ago

Thanks @aleksanderk I added a commit to master which "fixes" the crash. It's quite a lot of boilerplate code to add to every property.

So I added another solution, which is more general. You can see it in the thread_safety branch. Basically we just have to use the method executeThreadSafe when dealing with the entities in background. And that solves the issue.

Please note I changed the core data model properties with a cb_ prefix. This is not necessary. I added it because I needed in the solution in master, but for the most cases, the managed objects will just adopt automatically the protocols, without any additional getter and setter (as it was before).