lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [lwip-users] Simple Multithreading question


From: Goldschmidt Simon
Subject: RE: [lwip-users] Simple Multithreading question
Date: Tue, 8 Jan 2008 13:39:53 +0100

Hi,
 
Multiple tcpip_threads are NOT SUPPORTED! Using tcpip_thread is a way to
achieve multithreading while the core of lwip is not thread-safe: every
thread that wants to use the stack must communicate with the single
tcpip_thread and this tcpip_thread is the only thread allowed to call
non-thread-safe corea functions (tcp, udp, ip, arp and so on).
 
The piece of code you posted communicates with tcpip_thread: it tells
the thread to execute a connect in its context (by posting 'msg') and
waits for this message to be processed (the connect is executed) by
waiting for exactly one message being posted to the conn->mbox. 'msg' is
allocated on the stack in more recent versions of lwip: it remains
allocated while tcpip_thread processes it since this is a synchronous
call.
 
Simoin
 


________________________________

        Von:
address@hidden
[mailto:address@hidden
Im Auftrag von Muhamad Ikhwan Ismail
        Gesendet: Dienstag, 8. Januar 2008 12:33
        An: address@hidden
        Betreff: [lwip-users] Simple Multithreading question
        
        

        Hi ! 
        
        I know its a bit too late but still Happy New Year !
        
        I am on the final phase of my project in implementing lwip v1.2
into PowerPC based MPC852T running an SMX OS.
        The single thread seems to work. The driver input and output
goes through tcpip_thread, and the OS emulation layer
        is working fine, and the intertask communication between the
netconn API and the TCPIP thread works too.
        Following are my questions :
        
        1 There is a piece of code in that puzzles me a little bit and
could someone explain this piece ? 
        
        if ((msg = (struct api_msg*)memp_malloc(MEMP_API_MSG)) == NULL)
{ 
             return ERR_MEM;
           }
           msg->type = API_MSG_CONNECT;
           msg->msg.conn = conn;  
           msg->msg.msg.bc.ipaddr = addr;
           msg->msg.msg.bc.port = port;
           api_msg_post(msg);
           sys_mbox_fetch(conn->mbox, NULL);
           memp_free(MEMP_API_MSG, msg);
         
          in netconn_connect() upon creating the message and posting it,
why are we fetching it back and then deallocate the messages. 
          I thought that the msg was meant to passed to the tcpip_thread
? And why are we deallocating the message now ? shouldnt we 
         deallocate the message after the tcpip thread finish working on
it? This piece of code would work in a single tcpip thread. But what if 
         I have multiple tcpip_thread in which i might end up
overwriting a message before it can be received by a tcpip_thread.
        
        2. I am suppose to make the whole thing now multithreading safe.
There will be multiple task which can open up to 64 sockets in total to
handle the
            communication in and out. My question is, can I have a
multiple tcpip_thread servicing all this sockets, or may i just have one
? If I can is there anything I need
           to be aware about other than simply creating multiple
tcpip_thread and those which have been discussed in the mailing list ?
        
        Thanks a lot for your answers. I really appreciate it.
        
        Greetings
        Ikhwan
        
         
        
        

________________________________

        Watch "Cause Effect," a show about real people making a real
difference. Learn more
<http://im.live.com/Messenger/IM/MTV/?source=text_watchcause>  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]