Skip to content

Add FreeBSD pthread support in ThreadPosix.swift#3593

Draft
rafaelcepeda wants to merge 12 commits into
apple:mainfrom
rafaelcepeda:freebsd-threadposix
Draft

Add FreeBSD pthread support in ThreadPosix.swift#3593
rafaelcepeda wants to merge 12 commits into
apple:mainfrom
rafaelcepeda:freebsd-threadposix

Conversation

@rafaelcepeda

Copy link
Copy Markdown
Contributor

Add FreeBSD thread naming and creation support to NIOPosix.

Motivation:

NIOPosix fails to compile on FreeBSD because ThreadPosix.swift has platform-specific handling for Linux, OpenBSD, and Darwin but FreeBSD falls through without defining ThreadDestructor, sys_pthread_getname_np, or sys_pthread_setname_np. The pthread_create call also fails because FreeBSD's pthread_t is an opaque pointer type that can't be zero-initialized like on Linux.

Modifications:

  • Added a #elseif os(FreeBSD) block importing CNIOFreeBSD and wiring sys_pthread_getname_np/sys_pthread_setname_np to the C wrappers, with the appropriate ThreadDestructor typealias.
  • Added os(FreeBSD) to the existing OpenBSD guard in sysPthread_create, since both BSDs use the same optional pthread_attr_t pattern.

Result:

ThreadPosix.swift compiles without errors on FreeBSD. Total NIOPosix error count drops from 89 to 75, eliminating all ThreadPosix-related errors.

@rafaelcepeda rafaelcepeda added the 🔨 semver/patch No public API change. label May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant