Is "print()" thread safe?

While I never read anything from Apple on this, I recall reading several posts mentioning that "println()" was not thread safe. The concern was both that characters might get interleaved to actual concerns about crashes.


Can anyone comment on the current Swift 2.0 (2.1beta?) situation?

Not sure on iOS, but on OSX I found it to be "thread-safe" in the sense that it doesn't crash. It _does_ interleave characters, so I wrote code to serialize it here:

https://github.com/rbrockerhoff/SwiftChecker/blob/master/SwiftChecker/Future.swift

after line#444.

Serializing print() to the main thread, though, means that things print()ed before a crash will get lost. Calling NSLog() seems to work better, but it prints timestamps and other cruft. Calling printf() may be the best solution, will do that in the next update.

As far as I know the whole Std Library is not thread safe.

Well, at some point — probably Swift 2.0 — it seems that print() was properly serialized, so I no longer see any interleaving of output when called from multiple threads. Can't recall seeing that in the release notes, however.

Is "print()" thread safe?
 
 
Q