0

To solve my assignment about readers/writers problem , I write the code using C language. I guess that pthread_create line occurs segmentation fault. How I success to run this code?

sorry, I don't know any solutions.

int count_r = 0;
int count_w=0;
sem_t wse;
sem_t rse;

int initialize(){
    sem_init(&wse, 0, 1);
    sem_init(&rse, 0, 1);
    return 0;}

void main(){
    int i;
    pthread_t tid[25];
    initialize();
    for(i=0;i<20;i++)
            pthread_create(&tid[i], NULL, &reader, NULL);
    for(i=20;i<25;i++)
            pthread_create(&tid[i], NULL, &writer, NULL);

segmentation fault..

  • [Have you tried to use a debugger?](https://stackoverflow.com/q/25385173) – Yastanub May 21 '19 at 13:28
  • Do you mind posting reader and writer functions ? oh, and you are storing readers and writers in same tid , which is not a good idea (actually totally wrong). – Gar May 21 '19 at 13:42
  • oh, cause was my huge mistake. I used "%n" instead of "%d" in readers and writers function. thank you for your kindness :) – 나기주 May 21 '19 at 15:28

0 Answers0