tags:

views:

84

answers:

2

I'm working on a project in C that requires threads running on separate CPUs than the initial process. I am using the pthread library to create these threads. I use sched_setaffinity to pin the main process to a cpu. Can I do the same for each thread to pin them to separate CPUs?

I am also pinning the memory of the main process. Will a call to mlockall(MCL_CURRENT|MCL_FUTURE) before creating pthreads pin all of the memory used by the pthreads as well or would I need to call it again within each pthread?

Thanks in advance.

+3  A: 

On linux you have pthread_attr_setaffinity_np, but as the np indicates this is non portable aka an extension.

Jens Gustedt
+2  A: 

Memory is shared between all the threads in a process, so it makes no sense to call mlockall more than once per process.

Besides, memory is shared by all the CPUs on a system. The mlockall API only prevents the operating system from writing the process's memory pages to disk and has nothing to do with locking memory to a CPU.

doron