crash Dictionary.subscript.getter

1.5k Views Asked by At

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

0

There are 0 best solutions below