*affinity* support

void78
void78

Sometime it's crucial for the application to handle incoming events as much as possible.
One of the possible way for that might be 'stealing' CPU core from the OS so does not participate in scheduling and bind your thread to that core.
Sure we can always make kind of cpu binder:

class ThreadCpuBinder
{
public:
   ThreadCpuBinder(int cpu)
   {
      if(cpu != -1)
      {
          cpu_set_t cpuSet;

          CPU_ZERO(&cpuSet);
          CPU_SET(cpu, &cpuSet);

          if(pthread_setaffinity_np(pthread_self(), sizeof(cpuSet), &cpuSet))
          {
              // error indication
          }
      }
   }
};

Hope you've got enough with that)
As for me I'd prefer to see 'cpu_set_t' class/struct (or whatever it will be called) which contains CPUs out thread/task/async is allowed to use.
Implementing that sort of class has one important property - backward compatibility: in case you do not care about affinity you can simple  ignore that parameter on creating stage.

4
рейтинг
Нет комментариев
Другие идеи
Группа создана, чтобы собирать предложения к стандарту C++, организовывать их внутренние обсуждения, помогать готовить их для отправки в комитет и защищать на общих собраниях в рабочей группе по С++ Международной организации по стандартизации (ISO).
Все предложения