multithreading - Why is my application not using all cores on Mac OS X? -


i have simple pthread program (should) spawn whole lot of threads spin , consume cpu. however, never see program taking more 1 of 4 cores on mac os x mavericks notebook.

theories why happening:

  • is os that's preventing 1 process taking on machine?
  • is os x scheduler tight affinity?
  • is kernel setting can tweak where?
  • is pthread implementation on os x hobbled in way?

i have no idea.

i'm asking because have serious application (written in d) i'd use cpu parallel work, simplest pthread program doesn't go on 1 core.

#include <pthread.h> #include <stdio.h>  void *waste_time(void* a) {     (int = 0; < 10000000; i++) {         printf("%d\n", i);     }      return null; }  int main(void) {     const int threads = 100;     pthread_t thread[threads];      (int = 0; < threads; i++) {         pthread_create(&thread[i], null, waste_time, null);     }      (int = 0; < threads; i++) {         pthread_join(thread[i], null);     }      return 0; } 

take printf() call out of waste_time() loop - it's being called 10000000 times! rid of entirely or put outside loop, before return.

the operation of waste_time() dominated c lib and, underneath os i/o, call, which, in order prevent disastrous multithread access stdout, has internal lock. lock serialises entire run of process , os can run it, (mostly) on 1 core.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -