Array problem - /lib/libgcc_s.so.1

alejandro910's Avatar
Newbie Member
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
0
Gene Poole's Avatar, Join Date: Nov 2009
Contributor
Are you using any kind of synchronization, or can just any thread read/write to messages[] at anytime?
0
alejandro910's Avatar
Newbie Member
i'm using mutex and condition variable to protect the array..
0
alejandro910's Avatar
Newbie Member
i found the error.. i forgot to put '\0' at the end of my string.. solved