I import a C library that defines a simple C function that prints some stuff to stdout: void libraryFunction(int, int)
. I call this function as shown below:
import Foundation
import MyCLibrary
@main
struct MySwiftPackage {
static func main() async {
await withTaskGroup(of: Void.self, body: { group in
group.addTask {
libraryFunction(0, 2500000)
}
group.addTask {
libraryFunction(2500001, 5000000)
}
group.addTask {
libraryFunction(5000001, 7500000)
}
group.addTask {
libraryFunction(7500001, 10000000)
}
})
}
}
The code compiles and runs. Results seem to always appear in sequential order from min..<max
. Is it defined behavior of TaskGroup to always execute its Tasks in sequential order? Similar to a serial dispatch queue? Just found it very cool and useful to be able to call and use C code concurrently like so but wasn't sure if this was considered "safe" or "defined".