Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Concurrency] Non-Sendable value can be accessed from Global-Actor-isolated Task And normal Task #76541

Open
kntkymt opened this issue Sep 18, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@kntkymt
Copy link

kntkymt commented Sep 18, 2024

Description

Non-Sendable value can be accessed from Global-Actor-isolated Task And normal Task concurrently.

Reproduction

the following code can be complied with no error/warning on swift 6 mode

final class Counter {
    var count = 0
}

@MainActor
func f() {
    let c = Counter()

    Task {
        c.count += 1
        print(c.count)
    }

    Task.detached {
        c.count += 1
        print(c.count)
    }
}

Expected behavior

should not be compiled. since c would be concurrently accessed from Task and Task.detached.

Environment

$ swiftc --version

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Additional information

it seems that let c won't be sent into MainActor's region when capturing Task { }

final class Counter {
    var count = 0
}

@MainActor
func f() {
    // [(c), {(), MainActor}]
    let c = Counter()

    // should be: [{(c), MainActor}]
    // actual: [(c), {(), MainActor}]?
    Task {
        c.count += 1
        print(c.count)
    }

    // should be Conflict: [{(c), task}, {(c), MainActor}]
    // actual: [{(c), task}, {(), MainActor}]?
    Task.detached {
        c.count += 1
        print(c.count)
    }
}
@kntkymt kntkymt added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant