I need your help to find the problem in this code: it's the main function of my program that simulates a multiprocessor system. I use thread library to build the Ram entity and all CPUs. Compiling there aren't problems and most of the executions work well. But, sometime, I launch the exe and after one or two prints, there is a segmentation fault.

So, I try to find it using gdb (without any response) and valgrind. The only thing that Valgrind told to me is that there was only a possibly lost (this is the messagge: 272 bytes in 1 blocks are possibly lost in loss record 1 of 1).

Ps. I write #include for each library function.

```
int main(int argc, char *argv[])
{
  if(argc!=3)
  syserr("Utilizzo: simulazione <numCpu> <ramDim>\n");

  pthread_t ram;
  ram_dim=atoi(argv[2]);

  int num_cpu=atoi(argv[1]);
  pthread_t cpu[num_cpu];

  command *cpu_info=(command *) malloc(sizeof(command)*num_cpu);
  request *buffer=(request *) malloc(sizeof(request));

  int curs, status;
  pthread_attr_t attr;

  pthread_attr_init(&attr);
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

  pthread_mutex_init(&ram_lock, NULL);
  vpthread_mutex_lock(&ram_lock);

  if((status=pthread_create(&ram, &attr, ram_job, (void *) buffer))!=0)
    syserr("Creazione thread Ram fallita.\n");

  pthread_mutex_init(&cpu_lock, NULL);
  pthread_mutex_init(&rw_lock, NULL);
  pthread_mutex_lock(&rw_lock);

  for(curs=0;curs<num_cpu;curs++)
  {
    cpu_info[curs].istr=buffer;
    cpu_info[curs].num_cpu=curs+1;

    if((status=pthread_create(&cpu[curs], &attr, cpu_job, (void *) &cpu_info[curs]))!=0)
        syserr("Creazione thread Cpu fallita.\n");
  }

  pthread_attr_destroy(&attr);

  for(curs=0;curs<num_cpu;curs++)
    pthread_join(cpu[curs], (void **) 0);

  free(buffer);
  free(cpu_info);
  pthread_mutex_destroy(&rw_lock);
  pthread_mutex_destroy(&cpu_lock);
  pthread_mutex_destroy(&ram_lock);

  return 0;

```

}