It is currently Sun, 16 Jun 2019 00:35:46 GMT

Author Message
 Strange error with pthreads
I'm having a strange error with FreeBSD that I can't figure out. I
wrote a multi-threaded server that executes an infinity loop and for
each accept connection it launchs a new thread do serve the client.
There's no point where you can exit the main loop. Sometimes the
program exit and generates no core dump, so it seems that the program
exited normally.

Does anyone has some idea of what can I do to figure out what's


Pedro Paulo Jr.

 Sun, 04 Jan 2004 02:12:23 GMT   
 Strange error with pthreads
The simplest thing is to run the server under a de{*filter*}.
Set a breakpoint on exit(), and look at the stack when
you reach exit().

Fletcher Glenn
to reply remove NOSPAM from my reply address

"Pedro Paulo Oliveira jr" <> wrote in message

 Sun, 04 Jan 2004 04:59:18 GMT   
 Strange error with pthreads

Ok. But the problem is that there's no exit() in the program, so the
only way to leave the main loop is having an exeception like a memory
fault or other kind of error. But normally this erros should generate
a core dump that should be useful to debug the application.

 Sun, 04 Jan 2004 20:22:40 GMT   
 Strange error with pthreads
Pedro Paulo Oliveira jr wrote:

Even so, you can still use the de{*filter*} to detect that the
program has found an exception and look at the stack when
it does.  The Solaris de{*filter*} will also detect C++ exceptions
and it will break when a throw() is about to be executed.

BTW - just because your code doesn't have an
exit does not mean that there isn't an exit in some
library routine.  In the past, I've found exit in the
strangest places.

                Fletcher Glenn
                email (remove the dashes)

 Mon, 05 Jan 2004 00:12:36 GMT   
 Strange error with pthreads

I'm posting the main loop to of the server. Note that the error occurs
randomly. And I'm detaching the thread.

unsigned ListenFunc()
        SOCKET          socketClient;
        struct sockaddr SockAddr;
        LPREQUEST       lpReq;
        unsigned int    nLen;
        DWORD           dwRet;
        int             pid;
        FILE    *       log_err;

        pthread_t  tid;             /* variable to hold thread ID */

        // Loop forever accepting connections
                // Block on accept()
                nLen = sizeof(struct sockaddr);
                socketClient = accept(listenSocket, &SockAddr, &nLen);
                if (socketClient == -1)
                        log_err = fopen ("Errlog.txt","at");
                        if (log_err != NULL) {
                                fprintf (log_err,"%s\n",strerror(errno));
                                fclose (log_err);

                // Allocate struct for client and fill in defaults
                lpReq = (struct tagREQUEST*)malloc(sizeof(REQUEST));
                if (lpReq == NULL)
                lpReq->Socket = socketClient;

                // Start a client thread to handle this request
                pthread_create (&tid,NULL,ClientFunc,(void*)lpReq);
                pthread_detach (tid);
        log_err = fopen ("Errlog.txt","at");        
        if (log_err != NULL) {
                fprintf (log_err,"Error exit infinity loop! It should not reach
                fclose (log_err);
        return 0;

The system used is an 1Ghz AMD Athlon running FreeBSD 4.3 with 256 MB
of RAM.

 Mon, 05 Jan 2004 20:29:11 GMT   
 Strange error with pthreads (Pedro Paulo Oliveira jr) wrote in message <>...

How are you linking the libraries?

If you're doing something like: -lc -lpthreads, I mean, the order, probably
is the cause of your problem. Then, try -lpthreads -lc. Also, note that
the C standard library should be the last one to link.

 Wed, 07 Jan 2004 03:28:45 GMT   
 Strange error with pthreads

I'm posting here the Makefile.

# Search module

# Construct a .o file from a .c file with the same name.
        ${CC} $(CCFLAGS) $(UDEFINES) $(DEFINES) $(INCLUDES) -o $@ -c $<

interface : interface.o bst.o readabletimeout.o
        gcc $(CFLAGS) -o interface interface.o bst.o readabletimeout.cpp $(LIBDI
R) -lm -pthread

bst.o : bst.cpp
        gcc -c $(CFLAGS) $(INCLUDEDIR) bst.cpp

interface.o : interface.cpp
        gcc -c $(CFLAGS) $(INCLUDEDIR) interface.cpp

readabletimeout.o : readabletimeout.cpp
        gcc -c $(CFLAGS) $(INCLUDEDIR) readabletimeout.cpp

 Thu, 08 Jan 2004 01:53:56 GMT   
   [ 7 post ] 

Similar Threads

1. Strange error with pthreads

2. Strange SMP (pthreads) scalability problem

3. Strange pthreads problem on Solaris

4. strange pthreads behaviour

5. Strange Strange SPARQ error

6. Strange error message, very strange ...

7. Errors compiling with ftok(), struct timespec, and pthreads

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software