-3

C プログラミングと複数のスレッドを学習しようとしています。[次のような] 基本的なものをいくつかプログラミングし始めましたが、行き詰まりました。誰か手を貸してくれませんか?

program.c

#include <string.h>
#include <stdio.h>
#include <pthread.h>
#define NUM_THREADS 4

void *main_thread(void *threadID) {
    long tid;
    tid = (long)threadID;
    printf("main thread #%ld!\n", tid);
    pthread_exit(NULL);

}

void *first_thread(void *threadID) {
    long tid;
    tid = (long)threadID;
    printf("first thread #%ld!\n", tid);
    pthread_exit(NULL);

}

void *second_thread(void *threadID) {
    long tid;
    tid = (long)threadID;
    printf("second thread #%ld!\n", tid);
    pthread_exit(NULL);

}

void *last_thread(void *threadID) {
    long tid;
    tid = (long)threadID;
    printf("last thread #%ld!\n", tid);
    pthread_exit(NULL);

}



int main () {
    pthread_t threads[NUM_THREADS];
    int rc;
    long t;

    for (t=0; t < NUM_THREADS; t++) {
        printf("In main Function creating thread %ld\n", t);
        rc = pthread_create(&threads[t], NULL, first_thread, (void *)t);
        if (rc) {
            printf("ERROR; Return code from pthread_create is %d\n", rc);
            exit(-1);
        }

    }


    pthread_exit(NULL);
    return 0;
}

新しいことを見つけたら、上記のコードを更新し続けます*やあみんな。私はそれを適切にコンパイルしませんでしたが、今私は理解しました。gcc -pthread -o メイン main.c

4

1 に答える 1