Unix Programming - thread

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2005 > thread





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author thread
jessie

2005-11-04, 8:50 pm

I have the following code. It can be compiled throught. but when I debug
(gdb) it show a error 0xfefda6b0 in _ti_bind_guard () from
/usr/lib/libthread.so.1
.. I used g++ test4.cpp -g -lpthread -o test4 to compile.
please help

Thanks



#define _REENTRANT
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <sys/uio.h>
#include <unistd.h>
#include <thread.h>
#include <netdb.h>

/* the TCP port that is used for this example */
#define TCP_PORT 3001

/* function prototypes and global variables */
void *do_listen(void *);
void *do_timer(void *);
mutex_t lock;
int service_count;

main()
{
int sockfd, newsockfd, clilen, ret;
struct sockaddr_in cli_addr, serv_addr;
thread_t chld_thr, chld_thr1, chld_thr2, chld_thr3, chld_thr4, chld_thr5,
chld_thr6;


thr_create(NULL, 0, do_timer, (void *) NULL, THR_DETACHED, &chld_thr1);
thr_create(NULL, 0, do_listen, (void *) NULL, THR_DETACHED, &chld_thr);
return(0);
}


void *do_timer(void *arg)
{
for(;;){
sleep (3);
mutex_lock(&lock);
service_count++;
printf("Child thread [%d]: service_count [%d]\n", thr_self(),
service_count );
mutex_unlock(&lock);
}
}


void *do_listen(void *arg)
{
for(;;){
printf("do listen [%d]: Socket number = %d\n", thr_self());
}
}



Amphibient

2005-11-08, 6:29 pm

Is your gdb able to handle threads? this is probably the issue...

Also,

main() is historically declared in one of the following ways:

int main(void) {} <- I think you mean this
int main(int argc, char *argv[]) {} <- standard

for _ti_bind_guard info, check out:
http://cvs.opensolaris.org/source/x...#_ti_bind_guard

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com