为什么会error: syntax error at end of input???

时间:2020-11-26 22:47:03
编译提示如下错误: 没有语法错误啊,请问是为什么?
clone.c: In function `main':
clone.c:55: error: syntax error at end of input

#include <stdlib.h>
#include "semaphore.h"
#include "pthread.h"
int reader_function(int);
int writer_function(int);
char buffer[100];
sem_t product;
sem_t s;
pthread_mutex_t mutex;
main(){
        pthread_t reader,writer;
        pthread_mutex_init(&mutex,NULL);
        char *stack;
        int clone_flag,id,retval;
        clone_flag=CLONE_VM|CLONE_SIGHAND|CLONE_FS|CLONE_FILES;
        int i;
        for(i=1;i<=2;i++){
                id=i;
                stack=(char *)malloc(4096);                
                retval=clone((void *)writer_function,&(stack[4095]),clone_flag,&id);
                stack=(char *)malloc(4096);                
                retval=clone((void *)reader_function,&(stack[4095]),clone_flag,&id);
        }
        exit(1);
        int write_function(id){
                sem_wait(&s);
                pthread_mutex_lock(&mutex);
                if(id==1){                        
                printf("write function1 is running!\n");
                        sprintf(buffer,"aaa\n",100);                }
                else{                        
                        printf("write function2 is runing!\n");
                        sprintf(buffer,"bbb\n",100);
                }                pthread_mutex_unlock(&mutex);
                sem_post(&s);
        }        int read_function(id){
                sem_wait(&product);
                pthread_mutex_lock(&mutex);
                if(id==1){                        
                        printf("buffer was read by reader 1!\n");
                        printf("%s\n",buffer);
                }                else {                        
                        printf("buffer was read by reader 2!\n");
                        printf("%s\n",buffer);
                }                pthread_mutex_unlock(&mutex);
                sem_post(&product);
        }

2 个解决方案

#1


很明显最后少一个大括号。看看是否这个问题。

#2


底下又多出一个括号

#1


很明显最后少一个大括号。看看是否这个问题。

#2


底下又多出一个括号