19 Temmuz 2021 Pazartesi

pthread_setaffinity_np metodu

Giriş
Bu metod standart olmayan GNU fonksiyonudur (_np uzantısı nonportable demek) ve threadin hangi mantıksal işlemciye bağlanmak istendiği belirtilir. Açıklaması şöyle
Platform specific API's do have the ability to specify specific logical core (or a set of such cores) for a software thread. For example, GNU has pthread_setaffinity_np.
Örnek
Şöyle yaparız.
int cpuNum = ...
cpu_set_t cpus;
CPU_ZERO(&cpus);
CPU_SET(cpuNum, &cpus);

if(pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpus) != 0)  {
...Error...
}

Hiç yorum yok:

Yorum Gönder