Loading...

mt-smp@lists.apple.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: Thread Affinity - posix vs. cocoa threads George Warner Wed Jul 16 05:08:07 2008

on 7/9/08 6:30 AM, Markus Stürmer at
<[EMAIL PROTECTED]> wrote:
>> I have created a small demo program I've attached with this email.
>> It starts a number of "thread pairs" which operate on a common
>> volatile int, flipping it's value from 0 to 1. On the command lines,
>> the number of thread pairs and an affinity tag for each thread must
>> be given, e.g. "./pingpong 2 1 1 2 3" results in two thread pairs,
>> both threads of the first pair with affinity tag "1", and one thread
>> of the second pair has 2 and one 3.

Your "setaffinity" routine appears to set the affinity of "mac_thread_self"
and ignore the passed in threadid:

inline void setaffinity(mach_port_t threadid, int tag) {
    struct thread_affinity_policy mypolicy;
    mypolicy.affinity_tag = tag;
    
    if (
        thread_policy_set(
            mach_thread_self(),
            THREAD_AFFINITY_POLICY,
            &mypolicy.affinity_tag,
            THREAD_AFFINITY_POLICY_COUNT
        ) != KERN_SUCCESS
    ) {
        std::cerr << "Setting affinity of thread ? (" << threadid << ")
failed!" << std::endl;
        exit(-1);
    } else {
        CDEBUG ("Sucessfully set affinity of thread (" << threadid << ") to
" << tag );
    }
}

This wouldn't be a problem for the SET_AFFINITY_DURING case but the
SET_AFFINITY_BEFORE case will always execute on the main thread... Right?
(my C-- skills are weak)

-- 
Enjoy,
George Warner,
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mt-smp mailing list      ([EMAIL PROTECTED])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mt-smp/alexiscircle%40gmail.com

This email sent to [EMAIL PROTECTED]