Open Suse 10 seg fault


 
Thread Tools Search this Thread
Top Forums Programming Open Suse 10 seg fault
# 1  
Old 09-20-2007
Open Suse 10 seg fault

Okay, so here is some code that when compiled on Fedora Core 6 works great, but when I compile and run it on OpenSuse 10 it gives back a seg fault when trying to join the 2nd thead.

Code:
#include <pthread.h>
#include <stdio.h>

int print_message_function( void *ptr );

int x = 1;

main()
{
        pthread_t thread1, thread2;
        int thread1result, thread2result;
        char *message1 = "Hello";
        char *message2 = "World";
        pthread_attr_t *pthread_attr_default = NULL;
        pthread_attr_t *pthread_attr_default2 = NULL;

        printf("Begin\n");
        pthread_create( &thread1, pthread_attr_default,
                        (void*)&print_message_function, (void*) message1);
        pthread_create(&thread2, pthread_attr_default2,
                        (void*)&print_message_function, (void*) message2);

        pthread_join(thread1, (void *)&thread1result);
        printf("\nEnd thread1 with %d\n", thread1result);

        pthread_join(thread2, (void *)&thread2result);
        printf("\nEnd thread2 with %d\n", thread2result);

        exit(0);
}

int print_message_function( void *ptr )
{
        char *message;
        message = (char *) ptr;
        printf("%s ", message);
        fflush(stdout);
        return x++;
}

I compile using the -lpthread flag. Doesn't anyone have any suggestions or know why?
# 2  
Old 09-20-2007
Lying about prototypes and return types doesn't help.

The function prototype for a thread is

void *my_func(void *);

and the returned argument from a pthread_join is a void *.

Your typecasting as you have done it is unsafe.

So you should have

void *threadresult;

and

return (void *)x++;

Are you compiling with -D_REENTRANT ?
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. SuSE

g++ build on SUSE 12.1, cannot open included file

Hello, I have a project that I have compiled on a number of linux systems including CentOS, Ubuntu, and Windows Cygwin. I am trying to build the project under SUSE 12.1. The make file runs allot of the way through, but then throws an error that an included file can't be opened. This is the... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

2. IP Networking

Open Suse Router

Hello I am having some issues doing to routing I have 4 network cards and one is connected to a linksys router with everything turned off to give us a static ip to use for the gateway out to the internet. Hear is what we have We have eth2 with ip address of 192.168.1.2 / sub 255.255.255.0... (0 Replies)
Discussion started by: psutliff-una
0 Replies

3. Programming

'seg' assembly instruction in .s file

Is this x86? I encountered this instruction and can't seem to find any info on what it does anywhere. Any ideas? This is how it appears: seg es (4 Replies)
Discussion started by: stevenswj
4 Replies

4. Programming

Seg Fault Running AIX COBOL program

Hi some help read............ I'm getting a segmentation fault when I run an AIX COBOL/Db2 program. I initiate the program from the command line, but it hangs, and then when I press enter it generates a segmantation fault and produces a core dump. The box is running AIX software level ... (5 Replies)
Discussion started by: steve_f
5 Replies

5. Programming

Xlib Problem: XCloseDisplay seg fault

Hi, First of all forgive me if Xlib related problems does not go under this thread. In my main program, im using Xlib`s XImage type object which contains a regularly updating bitmap, and maps the XImage to a Xwindow using XPutImage. ( XCreateImage is used to create the XImage. ) The... (0 Replies)
Discussion started by: wolwy_pete
0 Replies

6. SuSE

open SUSE 11.0 and its printer configuration

Does anybody who uses open SUSE 11.0? I have used open SUSE 10.2 for about 18 months. Today I installed open SUSE 11.0 The printer does not work. I tried all the tricks tweak it. My printer is an old one. It is HP Deskjet 5600 series. It works fine. I did the configuration using... (0 Replies)
Discussion started by: Angelo
0 Replies

7. HP-UX

HP-UX 64 compilation causing some code to seg fault

Hello everyone, Today we are attempting to port some legacy C code to a 64 HP-UX machine at my company and there is kind of a strange error we ran into. there is a small function they have defined called zgetenv that accepts a char* and basically just does some null checking and returns ... (0 Replies)
Discussion started by: khadesh
0 Replies
Login or Register to Ask a Question