4 ms·
Can your CPU affinity wrappers be used with plain old java threads? Or does it only work with your realtime threads? I briefly inspected Affinity.java and it lo
by dclusin 12y ago
Can your CPU affinity wrappers be used with plain old java threads? Or does it only work with your realtime threads? I briefly inspected Affinity.java and it looks like it just takes the OS's thread ID so this may be fairly straightforward. Have you tried this?
- dljsjr 12y agoThe threadID used in the affinity wrapper maps to the address of a C++ object, so unfortunately no. To be more clear, it operates directly on pthreads under the hood, so if you had some way of grabbing the pthread information from a Java thread (this would obviously only work on Linux) you could maybe finagle it, but we haven't been interested in doing that. Our thread API is very similar to the Java Thread API, though, so it shouldn't be too tough to find a way to do what you want. EDIT: I may have been wrong about this, Jesper (the main author) says it should work out of the box, I think he's chiming in himself.
- dclusin 12y agoThanks for the info.
- jespersmith 12y agoHi, I'm the primary author of this library. Setting the thread affinity of the current thread should be possible using the Affinity.setAffinity(int... cpuID) call. Underneath, it calls sched_settaffinity(0, sizeof(set), &set); I'm not sure if this set the affinity of the whole process or just the thread. I suspect it is the calling thread. Let us know if you happen to find that out. Parsing the CPU layout of the machine you're running does not depend on any realtimethread code, and should work on any modern linux system.