Speicherverlust beim C-MultithreadingLinux

Linux verstehen
Anonymous
 Speicherverlust beim C-Multithreading

Post by Anonymous »

Ich weiß nicht, warum oder was undicht ist, aber es funktioniert nicht richtig. Leider hätte kein Chatbot diese Frage lösen können. Irgendwelche Ideen. Stattdessen werden zufällige Werte ausgegeben.

Code: Select all

#include 
#include 
#include 

void* kwadrat(void* arg) {
int* x_ptr = *(int*)arg;
int x = *x_ptrl;
int wynik = x * x;
printf("%d\n", wynik);
return NULL;
}

int main(int argc, char* argv[]) {
int value, n = argc - 1;
pthread_t* thread = malloc(sizeof(pthread_t) * n);
int* tab = malloc(sizeof(int) * n);
for (int i = 0; i < n; i++) {
tab[i] = atoi(argv[i + 1]);
pthread_create(&thread[i], NULL, kwadrat, tab;
}

for (int i = 0; i < n; i++) {
pthread_join(thread[i], NULL);
}

free(thread);
free(tab);
return 0;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post