peter-lawrey/Java-Thread-Affinity — Issue #12: acquireLock not going through all cores
Author: drelum
Created: 2012-01-29 22:59:10+00:00
State: open

It seems that the following code in AffinityLock:

private static AffinityLock acquireLock(boolean bind, int cpuId, AffinityStrategy... strategies) {
synchronized (AffinityLock.class) {
for (AffinityStrategy strategy : strategies) {
for (int i = PROCESSORS - 1; i < 0; i--) {
AffinityLock al = LOCKS[i];
if (al.canReserve() && strategy.matches(cpuId, i)) {
al.assignCurrentThread(bind, false);
return al;
}
}
}
}

should be changed to

private static AffinityLock acquireLock(boolean bind, int cpuId, AffinityStrategy... strategies) {
synchronized (AffinityLock.class) {
for (AffinityStrategy strategy : strategies) {
for (int i = PROCESSORS - 1; i >= 0; i--) {
AffinityLock al = LOCKS[i];
if (al.canReserve() && strategy.matches(cpuId, i)) {
al.assignCurrentThread(bind, false);
return al;
}
}
}
}

Am I right?