Ver Mensaje Individual
  #5 (permalink)  
Antiguo 29/11/2013, 13:16
programDisciple
 
Fecha de Ingreso: noviembre-2013
Mensajes: 1
Antigüedad: 10 años, 5 meses
Puntos: 0
Respuesta: Violacion del segmento ('core 'generado)

Hola.

Yo tengo un problema parecido creando un pequeño programa con mulithreads.

Mi codigo es este y no entiendo biien el fallo

int main()
{
/*
* Put your test code here.
*/

unsigned int n2=0;


void spawnThreads( unsigned int n );

printf("MAIN-par: Enter the number of threads (0 to 255): ");
scanf(" %d", &n2);
spawnThreads( n2 );



return 0;
}




void spawnThreads( unsigned int n )
{
/* your code goes here */
int n2=(int)n;
pthread_t thread_id[n2];
int i, j;

for(i=0; i < n2; i++)
{
pthread_create( &thread_id[i], NULL, thread_function, NULL );
}

for(j=0; j < n2; j++)
{
pthread_join( thread_id[j], NULL);
}





/* avoid 'unused parameter' warning */
(void)n;
}



void *thread_function(void *arg)
{
char *str;
str=(char*)arg;
printf("%s\n",str);
printf("Thread number %ld\n", pthread_self());
pthread_mutex_lock( &mutex1 );
counter++;
pthread_mutex_unlock( &mutex1 );
return NULL;
}

Me sale el mismo fallo y no entiendo porque es el objetivo es crear un programa que imprima por pantalla los tip de los threads. Lo ejecuto en consola y me sale: Violación de segmento (`core' generado)

Necesito ayuda. Gracias