This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pthread?


Israel Fdez Cabrera <israel@seg.inf.cu> writes:

> Hi, may be this question is offtopic, sorry if this is the case, any way I'll 
> appresiate if someone tell me where to find a good mailing list about Linux 
> programming.

comp.os.linux.development.apps
comp.os.linux.development.system

> 
> Any way, my problem is with the following test code:
> 
> typedef void*(*ftype)(void*);
> 
> void *thread_test( void *arg ){
>      std::cout << "New Thread: " << *((int*)arg) << std::endl;
>      delete arg;

Calling delete on void* has undefined behavior, and may corrupt your
    heap. Do not do it.

> }
> 
> int main(int argc, char *argv[]){
>      
>      ftype function = thread_test;
>      for ( int i = 0; i < 10; i++ ){
>           pthread_t thread_handler;
>           int * _ni = new int;
>           *_ni = i;
>           int res = pthread_create( &thread_handler, NULL, function, _ni );
>           std::cout << "Main Thread" << std::endl;
>      }
> 
> 
>      return EXIT_SUCCESS;
> }
> 
> It compiles well, but when I run it, I get a signal 11, at debbug time I 
> notice the signal is generated when the pthread_create is called. Any hint?, 
> any linux-prog mailing list?
[snip]

Well, I am not running linux, but on freebsd5 using gcc 3.3 it prints:

    Main Thread
    Main Thread
    Main Thread
    Main Thread
    Main Thread
    Main Thread
    Main Thread
    Main Thread
    Main Thread
    Main Thread

So please post the output of gcc -v, your glibc version, and the
    output of uname -a . I suspect your gcc is misconfigured somehow. 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]