[PATCH v3.2] New functions pthread_[sg]etattr_default_np for default thread attributes

Carlos O'Donell carlos@redhat.com
Thu Jun 13 16:05:00 GMT 2013


On 06/12/2013 11:55 PM, Siddhesh Poyarekar wrote:
> +verify_affinity_result (pthread_attr_t *attr)
> +{
> +  cpu_set_t cpuset;
> +
> +  RETURN_IF_FAIL (pthread_attr_getaffinity_np, attr, sizeof (cpuset), &cpuset);

This will fail if booted on a system with more than 1024 possible CPUs.

You need to use sysconf(_SC_PROCESSORS_ONLN); to get the size of the
required set, allocate it, and then use that size in the call.

> +  if (!CPU_ISSET (0, &cpuset))
> +    {
> +      puts ("failed to set cpu affinity");
> +      return 1;
> +    }
> +
> +  return 0;
> +}

Cheers,
Carlos.



More information about the Libc-alpha mailing list