Yes. Thank you @ole . This would definitely be the prefered idiom when passing a reference into the pthread_create body:
let box = Unmanaged<ThreadBox>
.fromOpaque((p as UnsafeMutableRawPointer?)!)
.takeRetainedValue()
assumingMemoryBound would only make sense if you want to use a typed UnsafePointer inside the thread body:
let buffer = UnsafeMutablePointer<Int>.allocate(capacity: n)
pthread_create(&pt, nil, { p in
let buffer = (p as UnsafeMutableRawPointer?)!.assumingMemoryBound(to: Int.self)
// ...
}, buffer)