多线程问题

时间:2014-10-15 23:21:11

标签: posix

有人可以向我解释为什么我的全局数组wordCount只包含垃圾和0吗?这只是为我创建问题的代码的一小部分,我已经尝试过调试,但我正在使用ubuntu内部的虚拟机我不熟悉他们的调试工具。

int  wordCount[10];    //global int array
char buff[BUFFERSIZE]; //global char array



typedef struct myWorkers{
int startingPos;
int bounds;
int myId;
}myData,*PmyData;

void somefunction()
{
   //code
   //code
  for(i=0; i<THREADMAX;i++)
  {
    pDataArray[i]=(struct myWorkers *)malloc(sizeof(struct myWorkers));

    pDataArray[i]->startingPos=charDivided*i;

    pDataArray[i]->myId   =i;
    if(i!=(threadCount-1)){pDataArray[i]->bounds=charDivided;}
    else{pDataArray[i]->bounds=charDivided+charProcessed;}

    if(pthread_create(&ref,NULL,&myThreads,pDataArray[i]))
    {
        printf("error creating thread\n");
        return -1;
    }

   }
}


void *somefunctionname(void *void_ptr)
{

    PmyData pDataArray;
    pDataArray = (PmyData) void_ptr;
    int counter =0;
    int id = pDataArray->myId;
    int i  = pDataArray->startingPos;
    int j  = pDataArray->bounds;
     j     += i;

    for(i=i; i<j; i++)
    {
       if((buffer[i]==somedata......))
        ;
       else counter++;
    }
    wordCount[id] = counter;
    //  free(pDataArray);
    return;

 }       

0 个答案:

没有答案