1

What is the suggested way to set core affinity for thread in zig programming language? Can't find anything similar in the docs below:

1 Answers1

1

Setting core affinity isn't currently implemented in the standard library.

Since zig makes it very easy to bind to C functions, you can just use a @cImport() to load the platform-specific C headers containing the functions you would like to use, e.g. sched.h for sched_setaffinity(2), pthread.h for pthread_setaffinity_np(3) on Linux or winbase.h for SetThreadAffinityMask, SetProcessAffinityMask on Windows.

@cImport() will then give you back a scope that contains all these functions as if they were defined in Zig: https://ziglang.org/documentation/0.6.0/#Import-from-C-Header-File

s-ol
  • 1,674
  • 17
  • 28