I'm having several crashes that I've been unable to replicate
<compiler-generated> - Line 4370483668
specialized Dictionary.subscript.getter + 4370483668
I suspect this might be related with dictionaries not being accessed in a safe way due the use of several threads
The most common crash happens in this line
guard self.service?.handlers[id] != nil else {
service is a weak variable
any ideas or suggestions?
Do you think a .async(flags: .barrier)
could solve the issue? because I'm unable to replicate it.
this code is called via observers over a Realm database so the Unit test i've created does several threads that try to write the database at same time.
--UNIT TEST PSEUDO CODE--
func testDictionaryAccess()
{
for i in 0...3
{
dispatchGroup.enter()
DispatchQueue(label: "createActivityThreads").async {
create records on database()
dispatchGroup.leave()
}
}
dispatchGroup.wait()
XCTAssertTrue(true)
}
each loop iteration takes about 20 seconds to run
service
is a week variable... A variable of what? A class? dictionary? Something else? this code is called via observers over a Realm - what is being called, what's being observed and what's the process. Please review How to create a Minimal, Complete, and Verifiable example update and refine the question and we'll take a look.