2015-04-29 37 views
1

我使用linux編譯如下pthreads程序時相同的錯誤多次獲得:Pthread的程序返回預期的聲明說明符或Ⅰ型A之前A&A令牌

GCC -c -lpthread proj2_part1.c -lrt

#include <unistd.h>  
    #include <sys/types.h> 
    #include <errno.h>  
    #include <stdio.h>  
    #include <stdlib.h>  
    #include <pthread.h>  
    #include <string.h>  
    #include <semaphore.h> 
    #define BUFFER_SIZE 10 
    #define TRUE 1 

    struct cQueue{ 
    int *buffer; 
    int front, rear; 
    }*queue; 

    int count; 
    pthread_mutex_t mutex; 
    sem_t full, empty; 

    ........ 
    /*MAIN*/ 
    int main(int argc,char* argv[]) 
    { 
     int a=0, b=0, count =0, buff[BUFFER_SIZE]; 
     int p = atoi(argv[1]), c = atoi(argv[2]); 
     unsigned int s = atoi(argv[0]); 
     pthread_t prothread[p], conthread[c]; 

     /*Initialize Semaphores*/ 
     if (sem_init(&full,0,0) == -1) 
      printf("%s\n",strerror(errno)); 

if (sem_init(&empty,0,BUFFER_SIZE) == -1) 
      printf("%s\n",strerror(errno)); 

pthread_mutex_init(&mutex, NULL); 

/*Initialize Circular Queue*/ 
queue->buffer=buff; 
queue->front = queue->buffer[0]; 
queue->rear = queue->buffer[0]; 

if(argc!=3) 
{ 
     fprintf(stderr,"Syntax: ./a.out <int> <int> <int>"); 
     return -1; 
} 
if(s<0) 
{ 
     fprintf(stderr,"Argument %d must be positive value\n",s); 
     return -1; 
} 
else 
{ 
    /*Create producer threads*/ 
    int i; 
    for (i=0; i<p; i++) 
    { 
    b = pthread_create(&prothread[i], NULL, producerThread, (void*)argv[1]); 
    if (b<0) 
    { 
    printf("Error: unable to create thread, %d\n",b); 
    return -1; 
    } 
    } 
    /*Create consumer threads*/ 
int j; 
for (j=0; j<c; j++) 
(
    a = pthread_create(&conthread[j], NULL, consumerThread, (void*)argv[2]); 
    if (a<0) 
     { 
     printf("Error: unable to create thread, %d\n",a); 
     return -1; 
     } 
}  
sleep(atoi(argv[0])); 
} 
return 0; 
} 

我收到以下錯誤。我認爲這與我的信號量聲明有關。

proj2_part1.c:147:81: error: expected â)â before â;â token 
      a = pthread_create(&conthread[j], NULL, consumerThread, (void*)argv[2]); 
                       ^
     proj2_part1.c:153:6: error: expected â;â before â}â token}  
                   ^
     proj2_part1.c: At top level: 
     proj2_part1.c:156:6: error: expected identifier or â(â before âreturnâ 
     return 0; 
    ^
     proj2_part1.c:157:1: error: expected identifier or â(â before â}â token 
} 

回答

0

你已經使用了(,你的意思{

for (j=0; j<c; j++) 
(
+0

TYVM。我很慚愧地說,我找了多久。我不應該這麼晚編程 –

相關問題