spierce7

    spierce7

    8 months ago
    Why is there no such a thing as Volatile for Kotlin Native?
    p

    Paul Weber

    8 months ago
    https://kotlinlang.org/docs/native-concurrency.html https://kotlinlang.org/docs/native-immutability.html That would be the starting point in the docs. There are also some articles and videos of talks about the memory model around that are decent. Searching “kotlin native memory model” should net you something to start with at least.
    spierce7

    spierce7

    8 months ago
    I’m well aware of the Kotlin Native memory model. I’m just more asking why there is no volatile in Swift and Kotlin native. It seems necessary.
    p

    Paul Weber

    8 months ago
    In the swift world you generally synchronize variables with locks, semaphores, etc. There’s some atomic types https://www.swift.org/blog/swift-atomics/ It seems KM does support some atomics as well. What exactly do you need from
    volatile
    ? I’ve honestly never declared a
    volatile
    var in either C or Java, since one of my professors at uni argued against them. So I wouldn’t know what you’re looking for exactly. 🤷‍♀️
    p

    Paul Weber

    8 months ago
    Also, with the current “old” memory model of KM, variables get frozen anyways when handed off to another “thread”, therefore I don’t really get where volatile would help you.
    spierce7

    spierce7

    8 months ago
    So any time I access a variable from outside a semaphore / lock, from multiple threads, I’m in the habit of declaring it Volatile in Java, to ensure I’m not reading a cached value from a thread cache
    p

    Paul Weber

    8 months ago
    You’d generally use atomics or locks on iOS / Apple platforms. But like I said, since every variable should be owned by the “thread” or is frozen, this is not an issue that you will run into?
    With the new memory model I’m not entirely sure how this is handled. But maybe the blog posts on that topic give some insight.
    spierce7

    spierce7

    8 months ago
    I’m mostly considering this from the new memory model perspective