Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Array problem - /lib/libgcc_s.so.1 (http://www.go4expert.com/forums/array-lib-libgccsso1-t20672/)

alejandro910 15Jan2010 14:54

Array problem - /lib/libgcc_s.so.1
 
Hi, I'm writing a server in C that accepts messages from users through TCP/IP connection and then forwards them to a list of file descriptors that are connected to the server...

I use a global variable to store all incoming messages
char* messages[1000];

When a user connects to the server to send a message, i create a new therad that receives the message, saves it in the messages array, and print it with puts() in server screen. Then it signals another thread that will send this message to the list of file descriptors that are waiting for this message..

the problem is this:
the thread receives the signal, and tries to read the message that was previously saved in the array.. but when I'm trying to print it in the server screen, I get /lib/libgcc_s.so.1 instead of the message.. it's not an error, process still runs, but I get this.. and the clients that receive the message, also print this..

any idea why is this happening?

i use gcc in ubuntu 9.1

Gene Poole 15Jan2010 19:57

Re: Array problem - /lib/libgcc_s.so.1
 
Are you using any kind of synchronization, or can just any thread read/write to messages[] at anytime?

alejandro910 15Jan2010 23:04

Re: Array problem - /lib/libgcc_s.so.1
 
i'm using mutex and condition variable to protect the array..

alejandro910 16Jan2010 00:04

Re: Array problem - /lib/libgcc_s.so.1
 
i found the error.. i forgot to put '\0' at the end of my string.. solved


All times are GMT +5.5. The time now is 02:44.