#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define agents 5
int n = 0;
pthread_mutex_t tick_lock = PTHREAD_MUTEX_INITIALIZER;
void* sell (void* data) {
pthread_mutex_lock(&tick_lock); //is a mutex here really necessary???
scanf("%d", &n);
pthread_mutex_unlock(&tick_lock); }
main() {
int i=0;
pthread_t tas[agents];
void* returnv[agents];
for(i=0; i<agents; i++)
pthread_create(&tas, NULL, sell, NULL);
for(i=0; i<agents; i++)
pthread_join(tas, &returnv);
}
Posix threads problem...again...
Earlier today,i had again some problems with posix threads...
Some good people here in the forum helped me...
Actually,my "problematic" code,was running great on RedHat,but not on Mandrake...
Anyway...I'd like to ask you if you see anything wrong with the following (extremely simple) piece of code...
Each time i run it,i get "core dumps" message...
i can't really underestand why...
Any help would be really appreciated...
[Edited by - law_order on November 27, 2004 8:31:19 AM]
pthread_mutex_unlock(&tick_lock); } } ^
Syntax error. Where'd this extra '}' come from?
That shouldn't even compile.
Quote:Original post by Docpthread_mutex_unlock(&tick_lock); } } ^
Syntax error. Where'd this extra '}' come from?
That shouldn't even compile.
only here there's that error...i fixed that...that's not the real error..
Quote:Original post by hh10k
I'm not sure if it would cause the crash, but sell() as no return statement.
hi hh10k..i don't think that's the problem...
maybe it has to do with the general thread problems Linux have...
ah...i'm confused...
Quote:Original post by igni ferroque
Have you examined the core file with gdb? Let us know where it stops.
here is the core file made by cygwin...
in Mandrake it is also the same.Only the location of the file changes.
Exception: STATUS_ACCESS_VIOLATION at eip=610DE3A9eax=00000000 ebx=00000032 ecx=00000000 edx=0000000C esi=0085DB92 edi=611172A8ebp=0085F028 esp=0085DB00 program=C:\cygwin\bin\a.exe, pid 3460, thread unknown (0xD9C)cs=001B ds=0023 es=0023 fs=0038 gs=0000 ss=0023Stack trace:Frame Function Args0085F028 610DE3A9 (0085F208, 611172A8, 00403000, 0085F058)0085F048 610DA3E5 (00403000, 00000000, 0085F098, 610A940A)0085F058 6108DB9F (00000000, FFFFFFFF, 00000000, 00000000)0085F098 610A940A (0A0501B8, 0085F0D0, 610A9390, 0085F0C8)0085F0C8 61003E84 (00000D90, 00000D9C, 00002C1E, 00000000)0085FF98 61003E3A (00000000, 00000000, 00000000, 00000000)End of stack trace
oh...igni,,would it be possible for you to check if that second piece of code works on your machine?
because if it does,then something is wrong with the implementation of threads and not with my code...
Quote:oh...igni,,would it be possible for you to check if that second piece of code works on your machine?Code works on MacOS X, Solaris, and Linux 2.4 (the RH box). I'm reluctant to blame your threads implementation, I'm not sure what else it could be. I think the pthreads library is part of the glibc2 package. What version of glibc are you linking with?
Quote:Original post by igni ferroqueQuote:oh...igni,,would it be possible for you to check if that second piece of code works on your machine?Code works on MacOS X, Solaris, and Linux 2.4 (the RH box). I'm reluctant to blame your threads implementation, I'm not sure what else it could be. I think the pthreads library is part of the glibc2 package. What version of glibc are you linking with?
well..i'm using Mandrake 8.2 with gcc 2.96 and glibc2.2...
i don't know...could it be the compiler?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement