Giter VIP home page Giter VIP logo

Comments (9)

mikon63 avatar mikon63 commented on July 1, 2024

Same happens for aisShips.forEach { (mmsi: String, aisShip: Aisdata) ... }

from thread-safe-dictionary.

chrisvoronin avatar chrisvoronin commented on July 1, 2024

yep we have a very similar implementation for our thread safe dictionary, same error. Was looking to see if anyone ran into that and solved it.

from thread-safe-dictionary.

macaaw avatar macaaw commented on July 1, 2024

I'm also getting this. Has there been any fixes for this?

from thread-safe-dictionary.

iThink32 avatar iThink32 commented on July 1, 2024

@mikon63 @macaaw apologies for the long delay in replying, are you sure removeValue is the culprit? if so then ill try to make time to add a thread safe implementation for that as well.

from thread-safe-dictionary.

mikon63 avatar mikon63 commented on July 1, 2024

I believe the error results from traversing the dictionary and within this loop removing items, though I can't be absolutely sure. I found a workaround by writing the elements I need to remove in an array first and then traversing the new array to remove elements in the dictionary, so I am actually working with two independent collections now.

@objc func onAisPrune(_ timer: Timer)
{
let currentdate = Date()
var mmsiToRemove : [String] = []

    mmsiToRemove = aisShips.filter({ (mmsi: String, aisShip: Aisdata) in
        return currentdate.timeIntervalSince(aisShip.aisdate) > 20 * 60
    }).map({ (mmsi: String, aisShip: Aisdata) -> String in
        return mmsi
    })

    for mmsi in mmsiToRemove
    {
        nmea.dbLock.wait()
        aisShips.removeValue(forKey: mmsi)
        aisTracks.removeValue(forKey: mmsi)
        nmea.dbLock.signal()
        
        DispatchQueue.main.async {
            MapFactory.shared.removeAisTarget(mmsi: mmsi)
        }
    }
}

from thread-safe-dictionary.

iThink32 avatar iThink32 commented on July 1, 2024

Unfortunately guys I've tried creating an iterator and making that thread safe but that too doesn't work. As suggested the issue is in modifying a dictionary while iterating the same. Thinking about fixes will update you on the same.

from thread-safe-dictionary.

iThink32 avatar iThink32 commented on July 1, 2024

For all those who are on iOS 13+ do check out actors, it will help in removing the dependency on our good old DispatchQueue.

from thread-safe-dictionary.

brandFromNSK avatar brandFromNSK commented on July 1, 2024

I got this too. Try solution by adding code:

    public func forEach(_ body: ((key: V, value: T)) throws -> Void) rethrows {
        try concurrentQueue.sync {
            try dictionary.forEach(body)
        }
    }

from thread-safe-dictionary.

nikbhatt-cu avatar nikbhatt-cu commented on July 1, 2024

The removeValue and removeAll funds do an async dispatch, rather than sync. Could that be an issue? It's easy to switch to code to sync and try reproducing it.

from thread-safe-dictionary.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.