multithreading - All threads are executing at once -


I try to find the number of CPU cores using sources in C. Someone asked me to try to perform 40 threads at a time, make each thread for one second, and see how many simultaneously executed I really like my attitude, the problem is to execute my code Afterwards, the program is sleeping for 1 second, and after that all the threads are launched at one time (not included sleeping). Can somebody help me out?

  zero funk (zero * arg) {int n = (int *) arg; Sleep (1); Printf ("Exec nr:% d \ n", n); } Int main {zero} {int i; Time_t rawtime; Struct tm * timeinfo; Time (and raw time); Timenfo = local time (and raw time); Printf ("Current local time and date:% s", eskime (tyynfof)); {Pthread_create (& amp; th [i], NULL, func, (int *) i) for i (i = 0; i & lt; N; i ++); } (I = 0; i    

You will not be able to find the number of CPUs in this way, because the scheduler You can choose to run all your threads on the same core and leave the other core (more important) for the goods. Therefore, you should rely on some functionality provided by your OS. For example, the file on Linux provides information about the / proc / cpuinfo CPU. This file can be opened and parsed by any user-level program. Other operating systems provide different mechanisms.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -