プロセッサの負荷を発生させる簡単なテスト プログラムを作成します。6 つのスレッドをスローし、すべてのスレッドで pi を計算します。しかし、プロセッサはターゲット プラットフォーム (arm) で 3 つのスレッドしか生成しません。通常の Linux-PC で同じプログラムを実行すると、6 つのスレッドすべてが生成されます。
何が問題ですか?
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#define ITERATIONS 10000000000000
#define NUM_THREADS 6
void *calculate_pi(void *threadID) {
        double i;
        double pi;
        int add = 0;
        pi = 4;
        for (i = 0; i < ITERATIONS; i++) {
                if (add == 1) {
                        pi = pi + (4/(3+i*2));
                        add = 0;
                } else {
                        pi = pi - (4/(3+i*2));
                        add = 1;
                }
        }
        printf("pi from thread %d = %20lf in %20lf iterations\n", (int)threadID, pi, i);
        pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
        pthread_t threads[NUM_THREADS];
        int rc;
        int i;
        for ( i = 0 ; i < NUM_THREADS; i++) {
                rc = pthread_create(&threads[i], NULL, calculate_pi, (void *)i);
                if (rc) {
                        printf("ERROR; return code from pthread_create() is %d\n", rc);
                        exit(EXIT_FAILURE);
                }
        }
        for ( i = 0 ; i < NUM_THREADS; i++) {
                pthread_join(threads[i], NULL);
        }
        return(EXIT_SUCCESS);
}