m323/Sources/Aufgabe6/extra.swift
cediackermann 52525c4045
Aufgabe6: add extra exercises, remove Third runner
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 12:06:16 +02:00

31 lines
705 B
Swift

import Foundation
actor Warehouse {
var stock: Int = 10
func takeFromStock(amount: Int, thread: String) {
let localStock = stock
stock -= amount
print(thread)
}
}
@main
struct App {
static func main() async {
let warehouse = Warehouse()
let threadB = Task.detached {
await warehouse.takeFromStock(amount: 2, thread: "B")
}
let threadA = Task.detached {
await warehouse.takeFromStock(amount: 1, thread: "A")
}
_ = await threadB.result
_ = await threadA.result
let finalStock = await warehouse.stock
print("Endgültiger Lagerbestand: \(finalStock) Stück")
}
}