C: Array wird fehlerhaft an Thread übergeben

DKK007

PCGH-Community-Veteran(in)
C: Array wird fehlerhaft an Thread übergeben

Ich bin gerade dabei ein kleines Tool zu parallelisieren.

Allerdings wird das Array mit den Daten scheinbar fehlerhaft an die Threads übergeben. Sieht jemand, wo der Fehler ist?

Code:
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <pthread.h>




float sectorentropie(int16_t, uint8_t *);
void *Working(void *);


int NUM_THREADS = 1;


struct thread_data{
   int  thread_id;
   FILE* file1;
   FILE* file2;
   uint64_t startpos;
   uint64_t size;
   uint8_t seekmod;
   int16_t sectorsize;
   uint8_t* SectorBuffer;   
};


int main(int argc, char* argv[]) {  
  // Parameter: Dateiname, Filepart-Dateiname, Start, Größe


  printf("Anzahl der Argumente: %d\n", argc);
  printf("Pfad: %s\n", argv[0]); // Erstes Argument ausgeben


  
 
  // Die restlichen Argumente ausgeben:
  int i = 1;
  for(; i < argc; ++i)
    printf("Argument %d: %s\n", i, argv[i]);


  //Argumente verarbeiten.
    //help
  if (argc==1)
  {
    printf("imagesectorsentropie: Both input and output files must be specified. \n");
    printf("-> Usage: imagesectorsentropie imagefile entropiefile [Options] \n");
    printf("Try 'imagesectorsentropie --help' for more information. \n");
   
    return 0;
  }  


  if ((argc==2) && ( (strcmp(argv[1],"-h")==0) || (strcmp(argv[1], "--help")==0) || (strcmp(argv[1], "/h")==0)  || (strcmp(argv[1], "/help")==0) || 
      (strcmp(argv[1], "/hilfe")==0) || (strcmp(argv[1], "--hilfe")==0) || (strcmp(argv[1], "-?")==0) ) )
  {
    printf("ImageSectorsEntropie - Help \n");
    printf("\n");
    printf("+++ desc +++ \n");
    printf("-> Usage: imagesectorsentropie imagefile entropiefile [Options] \n");
    printf("\n");
    printf("Parameter / Options: \n");
    printf("  -h, --help, -?                    display this help and exit \n");
    printf("  -z, --sectorsize=<bytes>          sectorsize of imagefile \n"); 
    printf("  -t, --threadcount                 number of threads \n");  
    printf("  -p, --pos=<bytes>                 starting position of domain in input file [0] \n");
    printf("  -s, --size=<bytes>                maximum size of input data \n");   
    printf("  -m, --mod=<bytes>                 modulo seeking for sectors (deaktivated with 0, activated with 1) \n");  
    
    
    return 0;
  }


  if (argc>13)
  {
    printf("imagesectorsentropie: Too many arguments. \n");
    printf("-> Usage: imagesectorsentropie imagefile entropiefile [Options] \n");
    printf("Try 'imagesectorsentropie --help' for more information. \n");


    return 0;
  }


  if ((argc==3) || (argc==4) || (argc==5) || (argc==6) || (argc==7) || (argc==8) || (argc==9) || (argc==10) || (argc==11) || (argc==12) || (argc==13))
  {
    printf("File1: %s\n", argv[1]);
    printf("File2: %s\n", argv[2]);
    
    FILE* f1;
    FILE* f2;


    if ( access(argv[1],F_OK) != -1)
    {      
      f1 = fopen(argv[1],"r");
      if (f1 == NULL) 
      { 
        printf("Error: Zugriff auf Datei '%s' nicht möglich. Exit. \n",argv[1]);
        return 1;
      }
    }
    else
    {
      printf("Fehler: Die Datei '%s' existiert nicht. Exit. \n",argv[1]);
      return 2;
    }
    


    
    if ( access(argv[2],F_OK) != -1)
    {
      printf("Fehler: Die Datei '%s' existiert bereits. Exit. \n",argv[2]);
      return 3;
    }
    else
    {      
      f2 = fopen(argv[2],"w");
      if (f2 == NULL) 
      { 
        printf("Error: Zugriff auf Datei '%s' nicht möglich. Exit. \n",argv[2]);
        return 4;
      }
    }




    
    uint8_t threadcount = 0;
    int16_t sectorsize = 512; // 512 -- 4096
    uint64_t position = 0;
    uint64_t size = -1;   // == uint64.Max
    uint8_t seekmod = 0;


    int pos_set = 0;
    int sectorsize_set = 0;
    int size_set = 0;
    int threadcount_set = 0;
    int seekmod_set = 0;


    printf("h1 \n");
   
    if (argc>=4)
    {  
      if (argc==13)
      {
        if ((argc>=5) && ((strcmp(argv[3],"-t")==0)  || (strcmp(argv[3], "/t")==0)))
        {
          //threadcount = atoi (argv[4]);
          threadcount = strtoul (argv[4], NULL, 0);
          printf("Threadcount: %d \n",threadcount);
          threadcount_set = 1;
        }


        if ((argc>=7) && ((strcmp(argv[5],"-z")==0)  || (strcmp(argv[5], "/z")==0)))
        {
          //threadcount = atoi (argv[6]);
          sectorsize = strtoul (argv[6], NULL, 0);
          printf("Sectorsize: %d \n",sectorsize);
          sectorsize_set = 1;
        }


        if ((argc>=9) && ((strcmp(argv[7],"-p")==0)  || (strcmp(argv[7], "/p")==0)))
        {
          //position = atoi (argv[8]);
          position = strtoul (argv[8], NULL, 0);
          printf("Position: %lu \n",position);
          pos_set = 1;
        }


        if ((argc>=11) && ((strcmp(argv[9],"-s")==0)  || (strcmp(argv[9], "/s")==0)))
        {
          //size = atoi (argv[10]);
          size = strtoul (argv[10], NULL, 0);
          printf("Size: %lu \n",size);
          size_set = 1;
        }
        
        if ((argc==13) && ((strcmp(argv[11],"-m")==0)  || (strcmp(argv[11], "/m")==0)))
        {
          //size = atoi (argv[12]);
          seekmod = strtoul (argv[12], NULL, 0);
          printf("Seekmod: %lu \n",seekmod);
          seekmod_set = 1;
        }
      }
 
      printf("h1 ++ \n"); 


      if ((threadcount_set==0) || (pos_set==0) || (size_set==0))
      {
        char textA[15];
        char textB[20];


        //printf("h2 \n");


        int lenarg4 = strlen(argv[3]);


        //printf("h3  \n");
        //printf("%d  \n",lenarg4);




        if (lenarg4>=6)
        {         
          strncpy(textB, argv[3], 6);
          textB[6] = '\0';
          //printf("%s \n",textB);
        }


        if ( (strcmp(textB,"--pos=")==0) || (strcmp(textB,"--threadcount=")==0) )
        {
          if (strcmp(textB,"--pos=")==0)
          {
            //printf("%s \n",argv[3]);
        
            // strncpy(dest, src + beginIndex, endIndex - beginIndex);
            strncpy(textA, argv[3] + 6, lenarg4 -6);
            position = strtoul (textA, NULL, 0);
            printf("Position: %lu \n",position);
          }
          if (strcmp(textB,"--threadcount=")==0)
          {
            //printf("%s \n",argv[3]);
        
            // strncpy(dest, src + beginIndex, endIndex - beginIndex);
            strncpy(textA, argv[3] + 15, lenarg4 -15);
            threadcount = strtoul (textA, NULL, 0);
            printf("Threadcount: %d \n",threadcount);
          }
        }
        else
        {
          printf("Unknown parameter %s \n",argv[3]);
          return 0;
        }


      
        // size
        if (argc==5)
        {
          char textC[16];
          char textD[21];


          //printf("h5 \n");


          int lenarg5 = strlen(argv[4]);


          //printf("h6  \n");
          //printf("%d  \n",lenarg5);




          if (lenarg5>=7)
          {         
            strncpy(textD, argv[4], 7);
            textD[7] = '\0';
            //printf("%s \n",textD);
          }


          if (strcmp(textD,"--size=")==0)
          {
            //printf("%s \n",argv[4]);
        
            // strncpy(dest, src + beginIndex, endIndex - beginIndex);
            strncpy(textC, argv[4] + 7, lenarg5 -7);
            size = strtoul (textC, NULL, 0);
            printf("Size: %lu \n",size); 
          }
          else
          {
            printf("Unknown parameter %s \n",argv[4]);
            return 0;
          }
        } 
      }
  
    }
  


    //int16_t sectorsize = 512; // 512 -- 4096
    uint8_t Buffer[sectorsize];
 
    //Test
    int i1 = 0;
    while (i1<sectorsize) 
    {
      Buffer[i1] = 1 ; //rand() % 256;
      //Buffer[i1] = (8*i1) % 256;


     // printf("%d \n",Buffer[i1]);


      i1++;
    }
  
    float sentropie = -1;
    sentropie = sectorentropie(sectorsize, Buffer);


    printf("Test-Entropie: %f  \n",sentropie);


    //NUM_THREADS = 32;
    if (threadcount_set == 1)
    { 
      NUM_THREADS = threadcount;
    }


    pthread_t threads[NUM_THREADS];
    struct thread_data td[NUM_THREADS];
    int rc;
    int ti;
    
    for( ti=0; ti < NUM_THREADS; ti++ ){
      printf("main() : creating thread, %d  (%d)\n" , ti, NUM_THREADS);
      //rc = pthread_create(&threads[ti], NULL, PrintHello, (void *)ti );
      td[ti].thread_id = ti;
      //td[ti].message = "This is message";


      td[ti].file1 = f1;
      td[ti].file2 = f2;
      td[ti].startpos = 1;
      td[ti].size = size;
      td[ti].seekmod = seekmod;
      td[ti].sectorsize = sectorsize;
      //td[ti].SectorBuffer = *Buffer;   
      td[ti].SectorBuffer = (uint8_t*)malloc(sizeof(uint8_t) * sectorsize);
      td[ti].SectorBuffer = Buffer;


      //printf("Bytes: %d: %d, %d ,  %lu \n",i,SectorBuffer[i],b, ByteCount[b]);
   
      rc = pthread_create(&threads[i], NULL, Working, (void *)&td[ti]);
        
      if (rc){
        printf("Error:unable to create thread, %d  \n" , rc );
        exit(-1);
      }
    }
    
    pthread_exit(NULL);
  
    printf("***  \n");
  
    return 0;
  }


  return 0;
}


//sectorsize


float sectorentropie(int16_t sectorsize, uint8_t SectorBuffer[])
{
          /*  
            Int_Sum := 0;
            ShowMessage_text:='';
            j:=0;
            while j<256 do   // Bytes durchgehen.
              begin
                Int_Sum := Int_Sum+Unit2.ByteCount[j];
                ShowMessage_text:=ShowMessage_text+IntToStr(j)+': '+IntToStr(Unit2.ByteCount[j])+#13;


                //ShowMessage(ShowMessage_text+'SUM: '+IntToStr(Int_Sum));


                p := Unit2.ByteCount[j] / Form2.KNumberEdit3.ValueAsInt;
                if p>0
                  thenByteCount
                    sum := sum+ (p*math.log2(p));


                Unit2.ByteCount[j]:=0;
                inc(j);
              end;


           Entropie := -sum;
         */




  //char Buffer[sectorsize];
  
  uint64_t ByteCount[256]; 
  


  int intsum = 0;
  double p = 0;
  double sum = 0;
  float entropie;  
  
  int i = 0;
  while (i < 256)
  {
    ByteCount[i] = 0;
    i++;
  }


  i = 0;
  while (i < sectorsize)
  {
    uint8_t b = (uint8_t) SectorBuffer[i];
    ByteCount[b] = ByteCount[b]+1;


   // printf("Bytes: %d: %d, %d ,  %lu \n",i,SectorBuffer[i],b, ByteCount[b]);


    i++;
  }


  
  int j = 0;
  while (j < 256)
  {
    intsum = intsum + ByteCount[j];
    p = 1.0 * ByteCount[j] / sectorsize;  // sectorsize anpassen, wenn letzter Sektor verkürzt.
    if (p > 0)
      sum = sum + (p * log2l(p));
  
   // printf("a Entropie (%d): %lu, %d, %f, %f  \n",j,ByteCount[j],sectorsize,p,sum);
  
    ByteCount[j] = 0;
    j++;
  } 


  if (sum != 0)
  {
    entropie = -sum;
  } 
  else
  {
    entropie = 0;
  }


  return entropie;
}


void *Working(void *threadarg)
{
  struct thread_data *my_data;
  my_data = (struct thread_data *) threadarg;
  
  long tid;
  tid = (long)(*my_data).thread_id;
  printf("Hello World! -Working- Thread ID, %lu \n", tid);


  int i = 0;
  while (i < (*my_data).sectorsize)
  {
    printf("Bytes: %d: %d     (TID: %lu) \n",i,(*my_data).SectorBuffer[i], tid);


    i++;
  }
  
//  float sentropie = -1;
 // sentropie = sectorentropie((*my_data).sectorsize, (*my_data).SectorBuffer);


 // printf("Test-Entropie: %f     (TID: %lu) \n",sentropie, tid); 


  pthread_exit(NULL);
}

Ausgabe [Fehler rot markiert, normalerweise sollten da überall 1 stehen]:

'/home/forensik/Dokumente/ImageSectorsEntropie/a.out' '/media/forensik/Allgemeine und Digitale Forensik/Datenvirtualisierung und Wiederherstellen von Daten/Praktikum/1.1.1.E01' '/home/forensik/Dokumente/ImageSectorsEntropie/entropie.txt' -t 1 -z 512 -p 0 -s 0 -m 0
Anzahl der Argumente: 13
Pfad: /home/forensik/Dokumente/ImageSectorsEntropie/a.out
Argument 1: /media/forensik/Allgemeine und Digitale Forensik/Datenvirtualisierung und Wiederherstellen von Daten/Praktikum/1.1.1.E01
Argument 2: /home/forensik/Dokumente/ImageSectorsEntropie/entropie.txt
Argument 3: -t
Argument 4: 1
Argument 5: -z
Argument 6: 512
Argument 7: -p
Argument 8: 0
Argument 9: -s
Argument 10: 0
Argument 11: -m
Argument 12: 0
File1: /media/forensik/Allgemeine und Digitale Forensik/Datenvirtualisierung und Wiederherstellen von Daten/Praktikum/1.1.1.E01
File2: /home/forensik/Dokumente/ImageSectorsEntropie/entropie.txt
h1
Threadcount: 1
Sectorsize: 512
Position: 0
Size: 0
Seekmod: 0
h1 ++
Test-Entropie: 0.000000
main() : creating thread, 0 (1)
Hello World! -Working- Thread ID, 0
Bytes: 0: 1 (TID: 0)
Bytes: 1: 1 (TID: 0)
Bytes: 2: 1 (TID: 0)
Bytes: 3: 1 (TID: 0)
Bytes: 4: 1 (TID: 0)
Bytes: 5: 1 (TID: 0)
Bytes: 6: 1 (TID: 0)
Bytes: 7: 1 (TID: 0)
Bytes: 8: 1 (TID: 0)
Bytes: 9: 1 (TID: 0)
Bytes: 10: 1 (TID: 0)
Bytes: 11: 1 (TID: 0)
Bytes: 12: 1 (TID: 0)
Bytes: 13: 1 (TID: 0)
Bytes: 14: 1 (TID: 0)
Bytes: 15: 1 (TID: 0)
Bytes: 16: 1 (TID: 0)
Bytes: 17: 1 (TID: 0)
Bytes: 18: 1 (TID: 0)
Bytes: 19: 1 (TID: 0)
Bytes: 20: 1 (TID: 0)
Bytes: 21: 1 (TID: 0)
Bytes: 22: 1 (TID: 0)
Bytes: 23: 1 (TID: 0)
Bytes: 24: 1 (TID: 0)
Bytes: 25: 1 (TID: 0)
Bytes: 26: 1 (TID: 0)
Bytes: 27: 1 (TID: 0)
Bytes: 28: 1 (TID: 0)
Bytes: 29: 1 (TID: 0)
Bytes: 30: 1 (TID: 0)
Bytes: 31: 1 (TID: 0)
Bytes: 32: 1 (TID: 0)
Bytes: 33: 1 (TID: 0)
Bytes: 34: 1 (TID: 0)
Bytes: 35: 1 (TID: 0)
Bytes: 36: 1 (TID: 0)
Bytes: 37: 1 (TID: 0)
Bytes: 38: 1 (TID: 0)
Bytes: 39: 1 (TID: 0)
Bytes: 40: 1 (TID: 0)
Bytes: 41: 1 (TID: 0)
Bytes: 42: 1 (TID: 0)
Bytes: 43: 1 (TID: 0)
Bytes: 44: 1 (TID: 0)
Bytes: 45: 1 (TID: 0)
Bytes: 46: 1 (TID: 0)
Bytes: 47: 1 (TID: 0)
Bytes: 48: 1 (TID: 0)
Bytes: 49: 1 (TID: 0)
Bytes: 50: 1 (TID: 0)
Bytes: 51: 1 (TID: 0)
Bytes: 52: 1 (TID: 0)
Bytes: 53: 1 (TID: 0)
Bytes: 54: 1 (TID: 0)
Bytes: 55: 1 (TID: 0)
Bytes: 56: 1 (TID: 0)
Bytes: 57: 1 (TID: 0)
Bytes: 58: 1 (TID: 0)
Bytes: 59: 1 (TID: 0)
Bytes: 60: 1 (TID: 0)
Bytes: 61: 1 (TID: 0)
Bytes: 62: 1 (TID: 0)
Bytes: 63: 1 (TID: 0)
Bytes: 64: 1 (TID: 0)
Bytes: 65: 1 (TID: 0)
Bytes: 66: 1 (TID: 0)
Bytes: 67: 1 (TID: 0)
Bytes: 68: 1 (TID: 0)
Bytes: 69: 1 (TID: 0)
Bytes: 70: 1 (TID: 0)
Bytes: 71: 1 (TID: 0)
Bytes: 72: 1 (TID: 0)
Bytes: 73: 1 (TID: 0)
Bytes: 74: 1 (TID: 0)
Bytes: 75: 1 (TID: 0)
Bytes: 76: 1 (TID: 0)
Bytes: 77: 1 (TID: 0)
Bytes: 78: 1 (TID: 0)
Bytes: 79: 1 (TID: 0)
Bytes: 80: 1 (TID: 0)
Bytes: 81: 1 (TID: 0)
Bytes: 82: 1 (TID: 0)
Bytes: 83: 1 (TID: 0)
Bytes: 84: 1 (TID: 0)
Bytes: 85: 1 (TID: 0)
Bytes: 86: 1 (TID: 0)
Bytes: 87: 1 (TID: 0)
Bytes: 88: 0 (TID: 0)
Bytes: 89: 103 (TID: 0)
Bytes: 90: 96 (TID: 0)
Bytes: 91: 24 (TID: 0)
Bytes: 92: 194 (TID: 0)
Bytes: 93: 127 (TID: 0)
Bytes: 94: 0 (TID: 0)
Bytes: 95: 0 (TID: 0)
Bytes: 96: 1 (TID: 0)
Bytes: 97: 1 (TID: 0)
Bytes: 98: 1 (TID: 0)
Bytes: 99: 1 (TID: 0)
Bytes: 100: 1 (TID: 0)
Bytes: 101: 1 (TID: 0)
Bytes: 102: 1 (TID: 0)
Bytes: 103: 1 (TID: 0)
Bytes: 104: 1 (TID: 0)
Bytes: 105: 1 (TID: 0)
Bytes: 106: 1 (TID: 0)
Bytes: 107: 1 (TID: 0)
Bytes: 108: 1 (TID: 0)
Bytes: 109: 1 (TID: 0)
Bytes: 110: 1 (TID: 0)
Bytes: 111: 1 (TID: 0)
Bytes: 112: 1 (TID: 0)
Bytes: 113: 1 (TID: 0)
Bytes: 114: 1 (TID: 0)
Bytes: 115: 1 (TID: 0)
Bytes: 116: 1 (TID: 0)
Bytes: 117: 1 (TID: 0)
Bytes: 118: 1 (TID: 0)
Bytes: 119: 1 (TID: 0)
Bytes: 120: 1 (TID: 0)
Bytes: 121: 1 (TID: 0)
Bytes: 122: 1 (TID: 0)
Bytes: 123: 1 (TID: 0)
Bytes: 124: 1 (TID: 0)
Bytes: 125: 1 (TID: 0)
Bytes: 126: 1 (TID: 0)
Bytes: 127: 1 (TID: 0)
Bytes: 128: 1 (TID: 0)
Bytes: 129: 1 (TID: 0)
Bytes: 130: 1 (TID: 0)
Bytes: 131: 1 (TID: 0)
Bytes: 132: 1 (TID: 0)
Bytes: 133: 1 (TID: 0)
Bytes: 134: 1 (TID: 0)
Bytes: 135: 1 (TID: 0)
Bytes: 136: 1 (TID: 0)
Bytes: 137: 1 (TID: 0)
Bytes: 138: 1 (TID: 0)
Bytes: 139: 1 (TID: 0)
Bytes: 140: 1 (TID: 0)
Bytes: 141: 1 (TID: 0)
Bytes: 142: 1 (TID: 0)
Bytes: 143: 1 (TID: 0)
Bytes: 144: 1 (TID: 0)
Bytes: 145: 1 (TID: 0)
Bytes: 146: 1 (TID: 0)
Bytes: 147: 1 (TID: 0)
Bytes: 148: 1 (TID: 0)
Bytes: 149: 1 (TID: 0)
Bytes: 150: 1 (TID: 0)
Bytes: 151: 1 (TID: 0)
Bytes: 152: 1 (TID: 0)
Bytes: 153: 1 (TID: 0)
Bytes: 154: 1 (TID: 0)
Bytes: 155: 1 (TID: 0)
Bytes: 156: 1 (TID: 0)
Bytes: 157: 1 (TID: 0)
Bytes: 158: 1 (TID: 0)
Bytes: 159: 1 (TID: 0)
Bytes: 160: 1 (TID: 0)
Bytes: 161: 1 (TID: 0)
Bytes: 162: 1 (TID: 0)
Bytes: 163: 1 (TID: 0)
Bytes: 164: 1 (TID: 0)
Bytes: 165: 1 (TID: 0)
Bytes: 166: 1 (TID: 0)
Bytes: 167: 1 (TID: 0)
Bytes: 168: 1 (TID: 0)
Bytes: 169: 1 (TID: 0)
Bytes: 170: 1 (TID: 0)
Bytes: 171: 1 (TID: 0)
Bytes: 172: 1 (TID: 0)
Bytes: 173: 1 (TID: 0)
Bytes: 174: 1 (TID: 0)
Bytes: 175: 1 (TID: 0)
Bytes: 176: 1 (TID: 0)
Bytes: 177: 1 (TID: 0)
Bytes: 178: 1 (TID: 0)
Bytes: 179: 1 (TID: 0)
Bytes: 180: 1 (TID: 0)
Bytes: 181: 1 (TID: 0)
Bytes: 182: 1 (TID: 0)
Bytes: 183: 1 (TID: 0)
Bytes: 184: 1 (TID: 0)
Bytes: 185: 1 (TID: 0)
Bytes: 186: 1 (TID: 0)
Bytes: 187: 1 (TID: 0)
Bytes: 188: 1 (TID: 0)
Bytes: 189: 1 (TID: 0)
Bytes: 190: 1 (TID: 0)
Bytes: 191: 1 (TID: 0)
Bytes: 192: 1 (TID: 0)
Bytes: 193: 1 (TID: 0)
Bytes: 194: 1 (TID: 0)
Bytes: 195: 1 (TID: 0)
Bytes: 196: 1 (TID: 0)
Bytes: 197: 1 (TID: 0)
Bytes: 198: 1 (TID: 0)
Bytes: 199: 1 (TID: 0)
Bytes: 200: 1 (TID: 0)
Bytes: 201: 1 (TID: 0)
Bytes: 202: 1 (TID: 0)
Bytes: 203: 1 (TID: 0)
Bytes: 204: 1 (TID: 0)
Bytes: 205: 1 (TID: 0)
Bytes: 206: 1 (TID: 0)
Bytes: 207: 1 (TID: 0)
Bytes: 208: 1 (TID: 0)
Bytes: 209: 1 (TID: 0)
Bytes: 210: 1 (TID: 0)
Bytes: 211: 1 (TID: 0)
Bytes: 212: 1 (TID: 0)
Bytes: 213: 1 (TID: 0)
Bytes: 214: 1 (TID: 0)
Bytes: 215: 1 (TID: 0)
Bytes: 216: 1 (TID: 0)
Bytes: 217: 1 (TID: 0)
Bytes: 218: 1 (TID: 0)
Bytes: 219: 1 (TID: 0)
Bytes: 220: 1 (TID: 0)
Bytes: 221: 1 (TID: 0)
Bytes: 222: 1 (TID: 0)
Bytes: 223: 1 (TID: 0)
Bytes: 224: 1 (TID: 0)
Bytes: 225: 1 (TID: 0)
Bytes: 226: 1 (TID: 0)
Bytes: 227: 1 (TID: 0)
Bytes: 228: 1 (TID: 0)
Bytes: 229: 1 (TID: 0)
Bytes: 230: 1 (TID: 0)
Bytes: 231: 1 (TID: 0)
Bytes: 232: 1 (TID: 0)
Bytes: 233: 1 (TID: 0)
Bytes: 234: 1 (TID: 0)
Bytes: 235: 1 (TID: 0)
Bytes: 236: 1 (TID: 0)
Bytes: 237: 1 (TID: 0)
Bytes: 238: 1 (TID: 0)
Bytes: 239: 1 (TID: 0)
Bytes: 240: 1 (TID: 0)
Bytes: 241: 1 (TID: 0)
Bytes: 242: 1 (TID: 0)
Bytes: 243: 1 (TID: 0)
Bytes: 244: 1 (TID: 0)
Bytes: 245: 1 (TID: 0)
Bytes: 246: 1 (TID: 0)
Bytes: 247: 1 (TID: 0)
Bytes: 248: 1 (TID: 0)
Bytes: 249: 1 (TID: 0)
Bytes: 250: 1 (TID: 0)
Bytes: 251: 1 (TID: 0)
Bytes: 252: 1 (TID: 0)
Bytes: 253: 1 (TID: 0)
Bytes: 254: 1 (TID: 0)
Bytes: 255: 1 (TID: 0)
Bytes: 256: 1 (TID: 0)
Bytes: 257: 1 (TID: 0)
Bytes: 258: 1 (TID: 0)
Bytes: 259: 1 (TID: 0)
Bytes: 260: 1 (TID: 0)
Bytes: 261: 1 (TID: 0)
Bytes: 262: 1 (TID: 0)
Bytes: 263: 1 (TID: 0)
Bytes: 264: 1 (TID: 0)
Bytes: 265: 1 (TID: 0)
Bytes: 266: 1 (TID: 0)
Bytes: 267: 1 (TID: 0)
Bytes: 268: 1 (TID: 0)
Bytes: 269: 1 (TID: 0)
Bytes: 270: 1 (TID: 0)
Bytes: 271: 1 (TID: 0)
Bytes: 272: 1 (TID: 0)
Bytes: 273: 1 (TID: 0)
Bytes: 274: 1 (TID: 0)
Bytes: 275: 1 (TID: 0)
Bytes: 276: 1 (TID: 0)
Bytes: 277: 1 (TID: 0)
Bytes: 278: 1 (TID: 0)
Bytes: 279: 1 (TID: 0)
Bytes: 280: 1 (TID: 0)
Bytes: 281: 1 (TID: 0)
Bytes: 282: 1 (TID: 0)
Bytes: 283: 1 (TID: 0)
Bytes: 284: 1 (TID: 0)
Bytes: 285: 1 (TID: 0)
Bytes: 286: 1 (TID: 0)
Bytes: 287: 1 (TID: 0)
Bytes: 288: 1 (TID: 0)
Bytes: 289: 1 (TID: 0)
Bytes: 290: 1 (TID: 0)
Bytes: 291: 1 (TID: 0)
Bytes: 292: 1 (TID: 0)
Bytes: 293: 1 (TID: 0)
Bytes: 294: 1 (TID: 0)
Bytes: 295: 1 (TID: 0)
Bytes: 296: 1 (TID: 0)
Bytes: 297: 1 (TID: 0)
Bytes: 298: 1 (TID: 0)
Bytes: 299: 1 (TID: 0)
Bytes: 300: 1 (TID: 0)
Bytes: 301: 1 (TID: 0)
Bytes: 302: 1 (TID: 0)
Bytes: 303: 1 (TID: 0)
Bytes: 304: 1 (TID: 0)
Bytes: 305: 1 (TID: 0)
Bytes: 306: 1 (TID: 0)
Bytes: 307: 1 (TID: 0)
Bytes: 308: 1 (TID: 0)
Bytes: 309: 1 (TID: 0)
Bytes: 310: 1 (TID: 0)
Bytes: 311: 1 (TID: 0)
Bytes: 312: 1 (TID: 0)
Bytes: 313: 1 (TID: 0)
Bytes: 314: 1 (TID: 0)
Bytes: 315: 1 (TID: 0)
Bytes: 316: 1 (TID: 0)
Bytes: 317: 1 (TID: 0)
Bytes: 318: 1 (TID: 0)
Bytes: 319: 1 (TID: 0)
Bytes: 320: 1 (TID: 0)
Bytes: 321: 1 (TID: 0)
Bytes: 322: 1 (TID: 0)
Bytes: 323: 1 (TID: 0)
Bytes: 324: 1 (TID: 0)
Bytes: 325: 1 (TID: 0)
Bytes: 326: 1 (TID: 0)
Bytes: 327: 1 (TID: 0)
Bytes: 328: 1 (TID: 0)
Bytes: 329: 1 (TID: 0)
Bytes: 330: 1 (TID: 0)
Bytes: 331: 1 (TID: 0)
Bytes: 332: 1 (TID: 0)
Bytes: 333: 1 (TID: 0)
Bytes: 334: 1 (TID: 0)
Bytes: 335: 1 (TID: 0)
Bytes: 336: 1 (TID: 0)
Bytes: 337: 1 (TID: 0)
Bytes: 338: 1 (TID: 0)
Bytes: 339: 1 (TID: 0)
Bytes: 340: 1 (TID: 0)
Bytes: 341: 1 (TID: 0)
Bytes: 342: 1 (TID: 0)
Bytes: 343: 1 (TID: 0)
Bytes: 344: 1 (TID: 0)
Bytes: 345: 1 (TID: 0)
Bytes: 346: 1 (TID: 0)
Bytes: 347: 1 (TID: 0)
Bytes: 348: 1 (TID: 0)
Bytes: 349: 1 (TID: 0)
Bytes: 350: 1 (TID: 0)
Bytes: 351: 1 (TID: 0)
Bytes: 352: 1 (TID: 0)
Bytes: 353: 1 (TID: 0)
Bytes: 354: 1 (TID: 0)
Bytes: 355: 1 (TID: 0)
Bytes: 356: 1 (TID: 0)
Bytes: 357: 1 (TID: 0)
Bytes: 358: 1 (TID: 0)
Bytes: 359: 1 (TID: 0)
Bytes: 360: 1 (TID: 0)
Bytes: 361: 1 (TID: 0)
Bytes: 362: 1 (TID: 0)
Bytes: 363: 1 (TID: 0)
Bytes: 364: 1 (TID: 0)
Bytes: 365: 1 (TID: 0)
Bytes: 366: 1 (TID: 0)
Bytes: 367: 1 (TID: 0)
Bytes: 368: 1 (TID: 0)
Bytes: 369: 1 (TID: 0)
Bytes: 370: 1 (TID: 0)
Bytes: 371: 1 (TID: 0)
Bytes: 372: 1 (TID: 0)
Bytes: 373: 1 (TID: 0)
Bytes: 374: 1 (TID: 0)
Bytes: 375: 1 (TID: 0)
Bytes: 376: 1 (TID: 0)
Bytes: 377: 1 (TID: 0)
Bytes: 378: 1 (TID: 0)
Bytes: 379: 1 (TID: 0)
Bytes: 380: 1 (TID: 0)
Bytes: 381: 1 (TID: 0)
Bytes: 382: 1 (TID: 0)
Bytes: 383: 1 (TID: 0)
Bytes: 384: 1 (TID: 0)
Bytes: 385: 1 (TID: 0)
Bytes: 386: 1 (TID: 0)
Bytes: 387: 1 (TID: 0)
Bytes: 388: 1 (TID: 0)
Bytes: 389: 1 (TID: 0)
Bytes: 390: 1 (TID: 0)
Bytes: 391: 1 (TID: 0)
Bytes: 392: 1 (TID: 0)
Bytes: 393: 1 (TID: 0)
Bytes: 394: 1 (TID: 0)
Bytes: 395: 1 (TID: 0)
Bytes: 396: 1 (TID: 0)
Bytes: 397: 1 (TID: 0)
Bytes: 398: 1 (TID: 0)
Bytes: 399: 1 (TID: 0)
Bytes: 400: 1 (TID: 0)
Bytes: 401: 1 (TID: 0)
Bytes: 402: 1 (TID: 0)
Bytes: 403: 1 (TID: 0)
Bytes: 404: 1 (TID: 0)
Bytes: 405: 1 (TID: 0)
Bytes: 406: 1 (TID: 0)
Bytes: 407: 1 (TID: 0)
Bytes: 408: 1 (TID: 0)
Bytes: 409: 1 (TID: 0)
Bytes: 410: 1 (TID: 0)
Bytes: 411: 1 (TID: 0)
Bytes: 412: 1 (TID: 0)
Bytes: 413: 1 (TID: 0)
Bytes: 414: 1 (TID: 0)
Bytes: 415: 1 (TID: 0)
Bytes: 416: 1 (TID: 0)
Bytes: 417: 1 (TID: 0)
Bytes: 418: 1 (TID: 0)
Bytes: 419: 1 (TID: 0)
Bytes: 420: 1 (TID: 0)
Bytes: 421: 1 (TID: 0)
Bytes: 422: 1 (TID: 0)
Bytes: 423: 1 (TID: 0)
Bytes: 424: 1 (TID: 0)
Bytes: 425: 1 (TID: 0)
Bytes: 426: 1 (TID: 0)
Bytes: 427: 1 (TID: 0)
Bytes: 428: 1 (TID: 0)
Bytes: 429: 1 (TID: 0)
Bytes: 430: 1 (TID: 0)
Bytes: 431: 1 (TID: 0)
Bytes: 432: 1 (TID: 0)
Bytes: 433: 1 (TID: 0)
Bytes: 434: 1 (TID: 0)
Bytes: 435: 1 (TID: 0)
Bytes: 436: 1 (TID: 0)
Bytes: 437: 1 (TID: 0)
Bytes: 438: 1 (TID: 0)
Bytes: 439: 1 (TID: 0)
Bytes: 440: 1 (TID: 0)
Bytes: 441: 1 (TID: 0)
Bytes: 442: 1 (TID: 0)
Bytes: 443: 1 (TID: 0)
Bytes: 444: 1 (TID: 0)
Bytes: 445: 1 (TID: 0)
Bytes: 446: 1 (TID: 0)
Bytes: 447: 1 (TID: 0)
Bytes: 448: 1 (TID: 0)
Bytes: 449: 1 (TID: 0)
Bytes: 450: 1 (TID: 0)
Bytes: 451: 1 (TID: 0)
Bytes: 452: 1 (TID: 0)
Bytes: 453: 1 (TID: 0)
Bytes: 454: 1 (TID: 0)
Bytes: 455: 1 (TID: 0)
Bytes: 456: 1 (TID: 0)
Bytes: 457: 1 (TID: 0)
Bytes: 458: 1 (TID: 0)
Bytes: 459: 1 (TID: 0)
Bytes: 460: 1 (TID: 0)
Bytes: 461: 1 (TID: 0)
Bytes: 462: 1 (TID: 0)
Bytes: 463: 1 (TID: 0)
Bytes: 464: 1 (TID: 0)
Bytes: 465: 1 (TID: 0)
Bytes: 466: 1 (TID: 0)
Bytes: 467: 1 (TID: 0)
Bytes: 468: 1 (TID: 0)
Bytes: 469: 1 (TID: 0)
Bytes: 470: 1 (TID: 0)
Bytes: 471: 1 (TID: 0)
Bytes: 472: 1 (TID: 0)
Bytes: 473: 1 (TID: 0)
Bytes: 474: 1 (TID: 0)
Bytes: 475: 1 (TID: 0)
Bytes: 476: 1 (TID: 0)
Bytes: 477: 1 (TID: 0)
Bytes: 478: 1 (TID: 0)
Bytes: 479: 1 (TID: 0)
Bytes: 480: 1 (TID: 0)
Bytes: 481: 1 (TID: 0)
Bytes: 482: 1 (TID: 0)
Bytes: 483: 1 (TID: 0)
Bytes: 484: 1 (TID: 0)
Bytes: 485: 1 (TID: 0)
Bytes: 486: 1 (TID: 0)
Bytes: 487: 1 (TID: 0)
Bytes: 488: 1 (TID: 0)
Bytes: 489: 1 (TID: 0)
Bytes: 490: 1 (TID: 0)
Bytes: 491: 1 (TID: 0)
Bytes: 492: 1 (TID: 0)
Bytes: 493: 1 (TID: 0)
Bytes: 494: 1 (TID: 0)
Bytes: 495: 1 (TID: 0)
Bytes: 496: 1 (TID: 0)
Bytes: 497: 1 (TID: 0)
Bytes: 498: 1 (TID: 0)
Bytes: 499: 1 (TID: 0)
Bytes: 500: 1 (TID: 0)
Bytes: 501: 1 (TID: 0)
Bytes: 502: 1 (TID: 0)
Bytes: 503: 1 (TID: 0)
Bytes: 504: 1 (TID: 0)
Bytes: 505: 1 (TID: 0)
Bytes: 506: 1 (TID: 0)
Bytes: 507: 1 (TID: 0)
Bytes: 508: 1 (TID: 0)
Bytes: 509: 1 (TID: 0)
Bytes: 510: 1 (TID: 0)
Bytes: 511: 1 (TID: 0)
 
AW: C: Array wird fehlerhaft an Thread übergeben

Moin,

der Fehler hat (noch) nicht's damit zu tun, wie du das Array übergibst - du zerlegst dir deinen Puffer selber: In der Schleife, wo du die Thread Datenstrukturen aufbaust:

Code:
    for( ti=0; ti < NUM_THREADS; ti++ ){
      printf("main() : creating thread, %d  (%d)\n" , ti, NUM_THREADS);
      //rc = pthread_create(&threads[ti], NULL, PrintHello, (void *)ti );
      td[ti].thread_id = ti;
      //td[ti].message = "This is message";


      td[ti].file1 = f1;
      td[ti].file2 = f2;
      td[ti].startpos = 1;
      td[ti].size = size;
      td[ti].seekmod = seekmod;
      td[ti].sectorsize = sectorsize;
      //td[ti].SectorBuffer = *Buffer;   
      td[ti].SectorBuffer = (uint8_t*)malloc(sizeof(uint8_t) * sectorsize);
      td[ti].SectorBuffer = Buffer;


      //printf("Bytes: %d: %d, %d ,  %lu \n",i,SectorBuffer[i],b, ByteCount[b]);
   
      rc = pthread_create(&threads[i], NULL, Working, (void *)&td[ti]); <<<<<<<<<<<<<<<<<<<<<<<<<<<
        
      if (rc){
        printf("Error:unable to create thread, %d  \n" , rc );
        exit(-1);
      }
    }


Du rufst pthread_create mit threads[i] auf. i ist abhängig von argc (bei mir 3), wenn man aber (wie bei mir) nur einen Thread hat, ist das threads-Array nur 1 groß. Du schreibst also über das Array "hinaus" -- und da liegt dann halt der Puffer.

Deswegen, gerade wenn's um zählen geht, am besten for-Schleifen wie
for(int i = 0; ...; ...)
Dann ist das i außerhalb der Schleife nicht mehr sichtbar... Stellenweise machst du das ja auch so, an anderen Stellen eher nicht (Gruppenarbeit?).

Auch sonst sind noch nen paar Sachen drin, unter anderem das hier:
Code:
      td[ti].SectorBuffer = (uint8_t*)malloc(sizeof(uint8_t) * sectorsize);
      td[ti].SectorBuffer = Buffer;
Ich vermute, dass du weißt, dass das nicht das tut was du (vermutlich) willst und nur zum testen ist?

Viele Grüße,
Matthias
 
Zurück