Realtime threads with Swift

dynamic structures like swift's array / dictionary / set are outlawed in real time safe code as they have internal reference types which could take locks (and cause memory allocation sometimes). taking a lock can take an unbounded amount of time, and real time code's main concern is hard limit on the time in the worst case scenario. (by the same logic if realtime code uses quicksort on arbitrary data it must assume its worst case O(n^2) performance, or switch to a true O(log(n)) worst case performance algorithm. swift "POD" structs only consisting of other POD structs and simple fixed types like bool / int / double / etc (but not dynamic types like string, data / url / etc) are realtime safe, and in swift we don't have the equivalent of C arrays, any algorithm that needs arrays would have to emulate them somehow (e.g. using preallocated memory + memmove).

1 Like