diff --git a/Software/Development/System/Linux/User/API/Linux_进程_线程与_CPU_的亲和性(Affinity).md b/Software/Development/System/Linux/User/API/Linux_进程_线程与_CPU_的亲和性(Affinity).md index a5cfe90..1664857 100644 --- a/Software/Development/System/Linux/User/API/Linux_进程_线程与_CPU_的亲和性(Affinity).md +++ b/Software/Development/System/Linux/User/API/Linux_进程_线程与_CPU_的亲和性(Affinity).md @@ -261,3 +261,20 @@ this thread 2812323584 is running in processor 1 this thread 2812323584 is running in processor 2 this thread 2812323584 is running in processor 3 ``` + +## 4.Android 系统的特殊说明 + +Android 系统屏蔽了 pthread_setaffinity_np() 函数,需要通过 syscall(__NR_sched_setaffinity) 替代: + +```cpp +void set_cur_thread_affinity(int mask) { + int err, syscallres; + pid_t pid = gettid(); + syscallres = syscall(__NR_sched_setaffinity, pid, sizeof(mask), &mask); + if (syscallres) { + err = errno; + LOGE("Error in the syscall setaffinity: mask = %d, err=%d",mask,errno); + } + LOGD("tid = %d has setted affinity success",pid); +} +```