Array problem - /lib/libgcc_s.so.1

Discussion in 'C' started by alejandro910, Jan 15, 2010.

  1. alejandro910

    alejandro910 New Member

    Joined:
    Jan 15, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    Are you using any kind of synchronization, or can just any thread read/write to messages[] at anytime?
     
  3. alejandro910

    alejandro910 New Member

    Joined:
    Jan 15, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    i'm using mutex and condition variable to protect the array..
     
  4. alejandro910

    alejandro910 New Member

    Joined:
    Jan 15, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    i found the error.. i forgot to put '\0' at the end of my string.. solved
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice