Witam ostatnio probowalem sie pobawic w napisnie prostego programu wielowatkowego i natrafilem na problem tego typu ze podczas uruchamiania na out mam : Segmentation Fault (core dumped)
Oto moj kod juz programu glownego bez funkcji ktore dolaczam dynamicznie. Pragne dodac ze program dzialajac w trybie "niewielowatkowym" nie wyrzycal zadnych bledow a zaimplementowane funkcje dzialaly poprawnie:
#include <stdlib.h>
#include <pthread.h>
#define N 10
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
void *funkcja_watku(void *argument);
void *funkcja_watku3(void *argument);
void *funkcja_watku2(void *argument);
typedef struct elemListPoziom {
struct elemListPoziom *next;
char *value;
int iloscElemPoziom;
} elemListPoziom;
typedef struct elemListPion {
struct elemListPion *next;
struct elemListPoziom *list;
int iloscElem;
} elemListPion;
typedef struct associativeArray {
elemListPion *tablica_asocjacyjna;
int sizePion;
} associativeArray;
typedef struct watek {
associativeArray *tablica;
int size;
}watek;
int main(){
//printf("test");
int i,j;
int sizePion, hashTest1, wybrany;
int pozycjaN;
pthread_t thread_id[N];
associativeArray *tablica_asocjacyjna1;
watek wateczek;
sizePion=10;
tablica_asocjacyjna1 = createAssociativeArray(sizePion);
wateczek.tablica=tablica_asocjacyjna1;
wateczek.size=sizePion;
for(i=0; i<2; i++) {
if(i % 2 == 0) {
pthread_create(&thread_id[i],NULL,funkcja_watku3,NULL);
}else{
pthread_create(&thread_id[i],NULL,funkcja_watku3,NULL);
}
}
for(j=0; j < N; j++){
pthread_join( thread_id[j], NULL);
}
system(EXIT_SUCCESS);
}
void *funkcja_watku (void *argument) {
watek* arg = (watek*) argument;
//char elem1[30] = "test";
pthread_mutex_lock( &mutex1 );
insertElemListPoziom(arg->tablica,"test");
pthread_mutex_unlock( &mutex1 );
return NULL;
}
void *funkcja_watku3 (void *argument) {
watek* arg = (watek*) argument;
pthread_mutex_lock( &mutex1 );
showAll(arg->tablica);
pthread_mutex_unlock( &mutex1 );
return NULL;
}
void *funkcja_watku_2 (void *argument) {
watek* arg = (watek*) argument;
pthread_mutex_lock( &mutex1 );
clearListPoziom(arg->tablica->tablica_asocjacyjna->list);
pthread_mutex_unlock( &mutex1 );
return NULL;
}