threaded apps crash in 2.2.10 on Alpha

Einar Floystad Dorum (einarfd@tihlde.org)
30 Jun 1999 15:39:26 +0200


On my SX164 running RH 6.0 (glibc 2.1, egcs 1.1.2) any program using
pthread will segfault or do an invalid instruction after a short
time. This happens on both 2.2.10 and 2.2.11-pre1 + Richard
Henderson's d-2211-rth1.gz. The enclosed pthread test program will
always segfault inside one of the pthread_* calls.

#include <pthread.h>
#include <malloc.h>
#include <stdio.h>
#define S_LEN 20480

void *consume(void *);
void *produce(void *);
long *work = NULL;

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

int main (void)
{

pthread_t thr1,thr2;

pthread_create(&thr2, NULL, produce, NULL);
pthread_create(&thr1, NULL, consume, NULL);

pthread_join(thr1,NULL);
pthread_join(thr2,NULL);

}
void *produce(void *p)
{
long i;
while(1){
pthread_mutex_lock(&lock);
if(work == NULL){
work = malloc(sizeof(long)*S_LEN);
if(work != NULL){
for( i = 0; i < S_LEN ; i++){
work[i] = 1;
}
}
}
pthread_mutex_unlock(&lock);
}
}

void *consume(void *p)
{
long sum,i;
while(1){
pthread_mutex_lock(&lock);
sum = 0;
if(work != NULL){
for(i = 0; i < S_LEN ; i++){
sum += work[i];
}
free(work);
work = NULL;
}
pthread_mutex_unlock(&lock);
}
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/