Boost logo

Boost :

Subject: Re: [boost] [thread] thread pining (processor affinity)
From: Johan Nilsson (r.johan.nilsson_at_[hidden])
Date: 2008-11-18 05:57:26


Oliver Kowalke wrote:
>> k-oli_at_[hidden] wrote:
>>> Hello Anthony,
>>> are you interessted in a function
>>> boost::this_thread::pin_to_processor( int)?
>>
>> Why not "set_affinity(<some type> processor_mask)"? It's more
>> general and uses well-established terminology.
>
> Most systems provide separate system calls for bind to one processor
> and set processor masks.
> So it is reasonable to provide additional functionality for setting
> the processor masks (not supported by many systems).

Binding to a single processor is only a specialization of the general case,
commonly supported or not.

>
>> Also, while you're at it, something like this would be valuable to
>> be able to specify when creating a thread as well.
>
> Do this only in the ctor is not generic - I saw a lot of code which
> binds the thread to one processor for some special computations and
> after finishing unbinding the thread.

I didn't say this should only be supported during thread creation, I wrote
"... as well".

For the case when you actually want a thread to run under a certain
processor all the time, you're possibly wasting CPU cycles when starting the
thread on an arbitrary processor, only to move the thread to a specific
processor immediately after that.

Coming to think of it, using the term "processor" is perhaps confusing as I
guess most people relate the word to a physical CPU. Maybe "execution unit"
or similar would be more generic.

/ Johan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk