Re: [lwip-users] LwIP multithread select mode problems

2016-07-03 Thread lampo
ok, I would use SYS_ARCH_PROTECT in my next  app version .  thanks a  lot,
Joe.



--
View this message in context: 
http://lwip.100.n7.nabble.com/LwIP-multithread-select-mode-problems-tp26561p26674.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LwIP multithread select mode problems

2016-06-28 Thread Joel Cunningham

See responses in-line



Joel


On Jun 24, 2016, at 09:31 PM, lampo  wrote:


thanks a lot.

now I use *recv*, *send*, *close* apis in the same thread per one
socket, that means each client socket occupy a new thread, and each of
them calles *select*, *recv*, *send*, *close* .

I'm wondering is this usage still so called multi-threaded environment
? can I just neglect SYS_ARCH_PROTECT here? for using
SYS_ARCH_PROTECT , there's really some bad thing happening inside the whole
schedule system. And it seems OK with 3 days of running without
SYS_ARCH_PROTECT .


I would say no.  The SYS_ARCH_PROTECT isn't just protecting against your 
application threads, but also the LwIP core thread and your application


If your port can't support SYS_ARCH_PROTECT in any of its forms (disable/enable 
interrupts, semaphore, mutex) then I would really question how safe that 
OS/platform is to use with LwIP in multi-threading mode.  How are the other SYS 
arch constructs (mbox, mutex, sem) working?



I just want to confirm the usage of SYS_ARCH_PROTECT, or where may
lead to data consistency problems due to not using SYS_ARCH_PROTECT
mechanism, when programing in this *specific multi-threaded environment *



If you want more confidence that your usage is safe, I think you're going to 
have to do analysis of the code to confirm no sections (that you are using) are 
unprotected.  I wouldn't want to perform that kind of analysis and would 
correctly implement SYS_ARCH_PROTECT


Appreciate for your advice!



--
View this message in context: 
http://lwip.100.n7.nabble.com/LwIP-multithread-select-mode-problems-tp26561p26584.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] LwIP multithread select mode problems

2016-06-24 Thread lampo
thanks a lot.

  now  I use *recv*,  *send*,   *close*  apis in the same thread per one
socket,   that means each client socket occupy a new thread, and each of
them calles *select*,  *recv*,  *send*,   *close* .

  I'm wondering  is this usage still so called  multi-threaded  environment
?  can I  just  neglect SYS_ARCH_PROTECT here? for using 
SYS_ARCH_PROTECT , there's really some bad thing happening inside the whole
schedule system.  And  it  seems  OK  with 3 days of running without
SYS_ARCH_PROTECT .

 I  just want  to  confirm the usage of SYS_ARCH_PROTECT,or where may
lead to data consistency problems  due to not using  SYS_ARCH_PROTECT
mechanism, when programing in this  *specific multi-threaded  environment * 

Appreciate for your advice! 



--
View this message in context: 
http://lwip.100.n7.nabble.com/LwIP-multithread-select-mode-problems-tp26561p26584.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LwIP multithread select mode problems

2016-06-24 Thread Joel Cunningham

Yes you need SYS_ARCH_PROTECT in a multi-threaded environment.  Whether or not 
you use SYS_LIGHTWEIGHT_PROT just controls whether the function prototypes are 
produced and used in SYS_ARCH_PROTECT:



#define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
#define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
#define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)


sys_prot_t sys_arch_protect(void);
void sys_arch_unprotect(sys_prot_t pval);


See the comments for how these should be implemented, you can use either 
interrupt disable/enable, semaphore or mutex



You can also define SYS_ARCH_PROTECT directly in sys_arch.h rather than going 
through a layer of sys_arch functions



Example:



sys_arch.h:

#define SYS_ARCH_DECL_PROTECT(lev) cpu_flags

#define SYS_ARCH_PROTECT(lev) level = disable_interrupts()

#define SYS_ARCH_UNPROTECT(lev) enable_interrupts(lev)



Joel


On Jun 23, 2016, at 09:33 PM, lampo  wrote:


thank you ! Joel

I still want to know if /SYS_ARCH_PROTECT/ is a must in multiple
threads environment?
I see a lot of /SYS_ARCH_PROTECT/ in select() and other sockets apis.

But when I set /SYS_LIGHATWEIGHT_PROT/ to 1 to use *SYS_ARCH_PROTECT*, the
applicaton run into hardfault or stackoverflow(due to RTOS thread scheduler,
or deadlock something ), I tried disabling interrupts and mutex both , in
implementing SYS_ARCH_PROTECT, both not ok.

I wonder if should use SYS_ARCH_PROTECT plus LWIP_NETCONN_SEM_PER_THREAD ?

Really appreciate!



--
View this message in context: 
http://lwip.100.n7.nabble.com/LwIP-multithread-select-mode-problems-tp26561p26573.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] LwIP multithread select mode problems

2016-06-24 Thread Sergio R. Caprile

Jin,
please don't hijack other people's threads.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LwIP multithread select mode problems

2016-06-23 Thread lampo
thank you !  Joel
  
   I still want to know if /SYS_ARCH_PROTECT/  is a must  in multiple
threads environment?
I see a lot of /SYS_ARCH_PROTECT/ in select() and other sockets apis. 

  But when I set /SYS_LIGHATWEIGHT_PROT/ to 1 to use *SYS_ARCH_PROTECT*, the
applicaton run into hardfault or stackoverflow(due to RTOS thread scheduler,
or deadlock something ), I tried disabling  interrupts and mutex both , in
implementing SYS_ARCH_PROTECT, both not ok.

 I wonder if should use SYS_ARCH_PROTECT plus  LWIP_NETCONN_SEM_PER_THREAD ?

Really appreciate!



--
View this message in context: 
http://lwip.100.n7.nabble.com/LwIP-multithread-select-mode-problems-tp26561p26573.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] LwIP multithread select mode problems

2016-06-23 Thread Noam Weissman
Hi Jin,


No problems, glad to help.


If you know C or Java JavaScript is simple... As for HTML and CSS its also not 
difficult to learn.

I am not talking about mastering it but rather have a basic plus understanding 
as you will find

out that you may/will need to make modifications to existing code.


Linux is more complicated then FreeRTOS from a system point of view (driver, 
boot loader etc..)

but again could be learned []


JSON is very simple so once you know the basics its ok.


I have many years of writing code behind me but I see that most of the jobs 
here (in Israel) are not

real embedded like you use but rather Linux etc... So you face the problems 
that I face here or actually

everywhere.


Learn more, advance your knowledge and hopefully you will find an interesting 
and rewarding job.


You can learn HTML, JS, CSS etc here:

   http://www.w3schools.com/



As for JSON here is the reference:

   http://www.json.org/



Good luck,

Noam.

JSON<http://www.json.org/>
www.json.org
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It 
is easy for humans to read and write. It is easy for machines to parse and 
generate.


W3Schools Online Web Tutorials<http://www.w3schools.com/>
www.w3schools.com
body { background-color: #d0e4fe;} h1 { color: orange; text-align: center;} p { 
font-family: "Times New Roman"; font-size: 20px;}





From: lwip-users <lwip-users-bounces+noam=silrd@nongnu.org> on behalf of 
Jin Won Seo <digital0w...@gmail.com>
Sent: Thursday, June 23, 2016 9:03 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] LwIP multithread select mode problems

Hi Noam,

I did not expect any replies, but you did. I appreciate your suggestions.

I am using Socket using Lwip and do not have any issues to handle semaphore, 
mutex, etc.. to manage tasks/threads using FreeRTOS. So, I think I can apply 
this skills to others.

I am working on embedded development using micro controller but I know xml and 
a little of HTML, not Java scripts and JSON.

Vancouver, Canada area where I live in has a few opportunities for doing that. 
There are more opportunities for only software side like Linux Kernel, so as 
for electrical/electronics guy like me it is hard to get into that side.

Again, I really appreciate your suggestions.

Regards,
Jin

On Thu, Jun 23, 2016 at 8:01 AM, Noam Weissman 
<n...@silrd.com<mailto:n...@silrd.com>> wrote:
Hi,

LwIP and FreeRTOS  are popular because they are open source and free.

If you understand how an OS works and have background in TCP/IP you should
not have a problem learning other TCP stack’s and/or other OS.

Finding a job is not only finding to work with something you are familiar with 
but
more than that. It is adapting/learning other systems and other tools.

If you only worked with LwIP RAW mode then I encourage you to learn some Socket
programing as this is much more common.

Most RT OS are similar, meaning they use semaphores, create tasks/threads, 
using queue’s etc…

If you are looking for a job, use the time in between to learn new skills. 
Learn some JS, XML,
JSON, HTML etc…


Good luck,
Noam.
From: lwip-users 
[mailto:lwip-users-bounces+noam<mailto:lwip-users-bounces%2Bnoam>=silrd@nongnu.org<mailto:silrd@nongnu.org>]
 On Behalf Of Jin Won Seo
Sent: Thursday, June 23, 2016 5:42 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] LwIP multithread select mode problems

Sorry for irrelevant reply, but I am so frustrated to find a job.
I used Lwip 1.4.1 in my project + RTOS, but ... almost nothing I can find.
Is this industry dead? These skill sets are not useful?


On Thu, Jun 23, 2016 at 7:33 AM, Joel Cunningham 
<joel.cunning...@me.com<mailto:joel.cunning...@me.com>> wrote:
Hi,

select() can be used by multiple threads at the same time and you can even have 
the same sockets in multiple calls and it will be safe.  The limitation comes 
from trying to use the same sockets from multiple simultaneous threads in other 
socket APIs (select is the exception, simultaneous send, recv, or close on the 
same socket is not supported, especially in 1.4.1).

In regards to the maxfd question, I think there is a small misunderstanding.  
The maxfd parameter in select() is the largest FD in your input FD_SETs + 1.  
This is because maxfd is used to iterate through the FD_SETs provided.  It has 
nothing to do with other threads calling select() or how many sockets are in 
the system, but the maximum value of any FDs in the current select() call.

Joel

On Jun 23, 2016, at 03:59 AM, lampo <lbg...@163.com<mailto:lbg...@163.com>> 
wrote:
hello,
can someone help me with multithread problem ?

we use lwip 1.4.1 in PLC products, and if it live through long time(1 month
for example) testing in industry use,
I will back here to report.

*our problem*
we use multithread select mode in our system, and it "seem

Re: [lwip-users] LwIP multithread select mode problems

2016-06-23 Thread Jin Won Seo
Hi Noam,

I did not expect any replies, but you did. I appreciate your suggestions.

I am using Socket using Lwip and do not have any issues to handle
semaphore, mutex, etc.. to manage tasks/threads using FreeRTOS. So, I think
I can apply this skills to others.

I am working on embedded development using micro controller but I know xml
and a little of HTML, not Java scripts and JSON.

Vancouver, Canada area where I live in has a few opportunities for doing
that. There are more opportunities for only software side like Linux
Kernel, so as for electrical/electronics guy like me it is hard to get into
that side.

Again, I really appreciate your suggestions.

Regards,
Jin

On Thu, Jun 23, 2016 at 8:01 AM, Noam Weissman <n...@silrd.com> wrote:

> Hi,
>
>
>
> LwIP and FreeRTOS  are popular because they are open source and free.
>
>
>
> If you understand how an OS works and have background in TCP/IP you should
>
> not have a problem learning other TCP stack’s and/or other OS.
>
>
>
> Finding a job is not only finding to work with something you are familiar
> with but
>
> more than that. It is adapting/learning other systems and other tools.
>
>
>
> If you only worked with LwIP RAW mode then I encourage you to learn some
> Socket
>
> programing as this is much more common.
>
>
>
> Most RT OS are similar, meaning they use semaphores, create tasks/threads,
> using queue’s etc…
>
>
>
> If you are looking for a job, use the time in between to learn new skills.
> Learn some JS, XML,
>
> JSON, HTML etc…
>
>
>
>
>
> Good luck,
>
> Noam.
>
> *From:* lwip-users [mailto:lwip-users-bounces+noam=silrd@nongnu.org] *On
> Behalf Of *Jin Won Seo
> *Sent:* Thursday, June 23, 2016 5:42 PM
> *To:* Mailing list for lwIP users
> *Subject:* Re: [lwip-users] LwIP multithread select mode problems
>
>
>
> Sorry for irrelevant reply, but I am so frustrated to find a job.
>
> I used Lwip 1.4.1 in my project + RTOS, but ... almost nothing I can find.
>
> Is this industry dead? These skill sets are not useful?
>
>
>
> On Thu, Jun 23, 2016 at 7:33 AM, Joel Cunningham <joel.cunning...@me.com>
> wrote:
>
> Hi,
>
>
>
> select() can be used by multiple threads at the same time and you can even
> have the same sockets in multiple calls and it will be safe.  The
> limitation comes from trying to use the same sockets from multiple
> simultaneous threads in other socket APIs (select is the exception,
> simultaneous send, recv, or close on the same socket is not supported,
> especially in 1.4.1).
>
>
>
> In regards to the maxfd question, I think there is a small
> misunderstanding.  The maxfd parameter in select() is the largest FD in
> your input FD_SETs + 1.  This is because maxfd is used to iterate through
> the FD_SETs provided.  It has nothing to do with other threads calling
> select() or how many sockets are in the system, but the maximum value of
> any FDs in the current select() call.
>
>
>
> Joel
>
>
> On Jun 23, 2016, at 03:59 AM, lampo <lbg...@163.com> wrote:
>
> hello,
> can someone help me with multithread problem ?
>
> we use lwip 1.4.1 in PLC products, and if it live through long time(1 month
> for example) testing in industry use,
> I will back here to report.
>
> *our problem*
> we use multithread select mode in our system, and it "seems" it's ok till
> now(1 days passed),
> but I see the doc in rawapi.txt,"/Netconn or Socket Api are not reentrant
> at
> the control bolck granularity level/" .
> so I really cannot figure out if im doing right thing.
>
> *our application background/restriction*
>
> a, our system is RTOS based , we need 2 TCP clients(separately connecting
> to
> 2 TCP servers, i.e., 2 lasers),
> 1 TCP server(deal with max of 4 remote clients,i.e.,4 modbus clients ), and
> 1 web server.
>
> b, lwip related thread cannot be in polling mode, for here is already a
> polling thread in RTOS and it has "soft real time" requirements.
>
> c, current lwip version is 1.4.1(we are evaluating 2.0.0)
>
> d, we need to send data to tcp servers periodically, 10 ms
>
> *our design/implementation *
>
> 3 thread has used 'select' , but the same socket is only closed by the
> thread who created it. here is details,
>
> we use 'select' in "user tcp client send thread" ,we first call
> 'connect',and then call 'select' to determine whether the socket is
> connected correctly or not; if some errors detected in connecting or data
> sending, we call 'close' to close the socket.
> we use 'select' in "user tcp client receive thread", blocked forever
> waiting for data, and call 'r

Re: [lwip-users] LwIP multithread select mode problems

2016-06-23 Thread Noam Weissman
Hi,

LwIP and FreeRTOS  are popular because they are open source and free.

If you understand how an OS works and have background in TCP/IP you should
not have a problem learning other TCP stack’s and/or other OS.

Finding a job is not only finding to work with something you are familiar with 
but
more than that. It is adapting/learning other systems and other tools.

If you only worked with LwIP RAW mode then I encourage you to learn some Socket
programing as this is much more common.

Most RT OS are similar, meaning they use semaphores, create tasks/threads, 
using queue’s etc…

If you are looking for a job, use the time in between to learn new skills. 
Learn some JS, XML,
JSON, HTML etc…


Good luck,
Noam.
From: lwip-users [mailto:lwip-users-bounces+noam=silrd@nongnu.org] On 
Behalf Of Jin Won Seo
Sent: Thursday, June 23, 2016 5:42 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] LwIP multithread select mode problems

Sorry for irrelevant reply, but I am so frustrated to find a job.
I used Lwip 1.4.1 in my project + RTOS, but ... almost nothing I can find.
Is this industry dead? These skill sets are not useful?


On Thu, Jun 23, 2016 at 7:33 AM, Joel Cunningham 
<joel.cunning...@me.com<mailto:joel.cunning...@me.com>> wrote:
Hi,

select() can be used by multiple threads at the same time and you can even have 
the same sockets in multiple calls and it will be safe.  The limitation comes 
from trying to use the same sockets from multiple simultaneous threads in other 
socket APIs (select is the exception, simultaneous send, recv, or close on the 
same socket is not supported, especially in 1.4.1).

In regards to the maxfd question, I think there is a small misunderstanding.  
The maxfd parameter in select() is the largest FD in your input FD_SETs + 1.  
This is because maxfd is used to iterate through the FD_SETs provided.  It has 
nothing to do with other threads calling select() or how many sockets are in 
the system, but the maximum value of any FDs in the current select() call.

Joel

On Jun 23, 2016, at 03:59 AM, lampo <lbg...@163.com<mailto:lbg...@163.com>> 
wrote:
hello,
can someone help me with multithread problem ?

we use lwip 1.4.1 in PLC products, and if it live through long time(1 month
for example) testing in industry use,
I will back here to report.

*our problem*
we use multithread select mode in our system, and it "seems" it's ok till
now(1 days passed),
but I see the doc in rawapi.txt,"/Netconn or Socket Api are not reentrant at
the control bolck granularity level/" .
so I really cannot figure out if im doing right thing.

*our application background/restriction*

a, our system is RTOS based , we need 2 TCP clients(separately connecting to
2 TCP servers, i.e., 2 lasers),
1 TCP server(deal with max of 4 remote clients,i.e.,4 modbus clients ), and
1 web server.

b, lwip related thread cannot be in polling mode, for here is already a
polling thread in RTOS and it has "soft real time" requirements.

c, current lwip version is 1.4.1(we are evaluating 2.0.0)

d, we need to send data to tcp servers periodically, 10 ms

*our design/implementation *

3 thread has used 'select' , but the same socket is only closed by the
thread who created it. here is details,

we use 'select' in "user tcp client send thread" ,we first call
'connect',and then call 'select' to determine whether the socket is
connected correctly or not; if some errors detected in connecting or data
sending, we call 'close' to close the socket.
we use 'select' in "user tcp client receive thread", blocked forever
waiting for data, and call 'recvfrom' if data received, if some errors
detected
in this thread,we don't just clost the socket ,but send message to "user tcp
client send thread" and tell it to close.
we use 'select' in "user tcp server thread",listening for incoming requests,
receiving and responding(sending) data.

*our doubt*
1、 ‘select’ can be used in multithread or not? if yes, the first param
maxfdp1 of lwip_select() must be set to the total number of sockets in each
thread?
for example,in our situation, maxfdp1 = 2(clients) + 4(remote clients) +
1(listen socket) in each select?

2、is SYS_ARCH_PROTECT must be used in multithread?

3、if lwip 1.4.1 does not support the multithread select mode, does lwip
2.0.0 supports it?

Thanks a lot !



--
View this message in context: 
http://lwip.100.n7.nabble.com/LwIP-multithread-select-mode-problems-tp26561.html
Sent from the lwip-users mailing list archive at Nabble.com<http://Nabble.com>.

___
lwip-users mailing list
lwip-users@nongnu.org<mailto:lwip-users@nongnu.org>
https://lists.nongnu.org/mailman/listinfo/lwip-users

___
lwip-users mailing list
lwip-users@nongnu.org<mailto:lwip-users@nongnu.org>
https://lists.nongnu.org/mailman/listinfo/lwip-users

__

Re: [lwip-users] LwIP multithread select mode problems

2016-06-23 Thread Jin Won Seo
Sorry for irrelevant reply, but I am so frustrated to find a job.
I used Lwip 1.4.1 in my project + RTOS, but ... almost nothing I can find.

Is this industry dead? These skill sets are not useful?



On Thu, Jun 23, 2016 at 7:33 AM, Joel Cunningham 
wrote:

> Hi,
>
> select() can be used by multiple threads at the same time and you can even
> have the same sockets in multiple calls and it will be safe.  The
> limitation comes from trying to use the same sockets from multiple
> simultaneous threads in other socket APIs (select is the exception,
> simultaneous send, recv, or close on the same socket is not supported,
> especially in 1.4.1).
>
> In regards to the maxfd question, I think there is a small
> misunderstanding.  The maxfd parameter in select() is the largest FD in
> your input FD_SETs + 1.  This is because maxfd is used to iterate through
> the FD_SETs provided.  It has nothing to do with other threads calling
> select() or how many sockets are in the system, but the maximum value of
> any FDs in the current select() call.
>
> Joel
>
> On Jun 23, 2016, at 03:59 AM, lampo  wrote:
>
> hello,
> can someone help me with multithread problem ?
>
> we use lwip 1.4.1 in PLC products, and if it live through long time(1 month
> for example) testing in industry use,
> I will back here to report.
>
> *our problem*
> we use multithread select mode in our system, and it "seems" it's ok till
> now(1 days passed),
> but I see the doc in rawapi.txt,"/Netconn or Socket Api are not reentrant
> at
> the control bolck granularity level/" .
> so I really cannot figure out if im doing right thing.
>
> *our application background/restriction*
>
> a, our system is RTOS based , we need 2 TCP clients(separately connecting
> to
> 2 TCP servers, i.e., 2 lasers),
> 1 TCP server(deal with max of 4 remote clients,i.e.,4 modbus clients ), and
> 1 web server.
>
> b, lwip related thread cannot be in polling mode, for here is already a
> polling thread in RTOS and it has "soft real time" requirements.
>
> c, current lwip version is 1.4.1(we are evaluating 2.0.0)
>
> d, we need to send data to tcp servers periodically, 10 ms
>
> *our design/implementation *
>
> 3 thread has used 'select' , but the same socket is only closed by the
> thread who created it. here is details,
>
> we use 'select' in "user tcp client send thread" ,we first call
> 'connect',and then call 'select' to determine whether the socket is
> connected correctly or not; if some errors detected in connecting or data
> sending, we call 'close' to close the socket.
> we use 'select' in "user tcp client receive thread", blocked forever
> waiting for data, and call 'recvfrom' if data received, if some errors
> detected
> in this thread,we don't just clost the socket ,but send message to "user
> tcp
> client send thread" and tell it to close.
> we use 'select' in "user tcp server thread",listening for incoming
> requests,
> receiving and responding(sending) data.
>
> *our doubt*
> 1、 ‘select’ can be used in multithread or not? if yes, the first param
> maxfdp1 of lwip_select() must be set to the total number of sockets in each
> thread?
> for example,in our situation, maxfdp1 = 2(clients) + 4(remote clients) +
> 1(listen socket) in each select?
>
> 2、is SYS_ARCH_PROTECT must be used in multithread?
>
> 3、if lwip 1.4.1 does not support the multithread select mode, does lwip
> 2.0.0 supports it?
>
> Thanks a lot !
>
>
>
> --
> View this message in context:
> http://lwip.100.n7.nabble.com/LwIP-multithread-select-mode-problems-tp26561.html
> Sent from the lwip-users mailing list archive at Nabble.com.
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] LwIP multithread select mode problems

2016-06-23 Thread Joel Cunningham

Hi,



select() can be used by multiple threads at the same time and you can even have 
the same sockets in multiple calls and it will be safe.  The limitation comes 
from trying to use the same sockets from multiple simultaneous threads in other 
socket APIs (select is the exception, simultaneous send, recv, or close on the 
same socket is not supported, especially in 1.4.1).



In regards to the maxfd question, I think there is a small misunderstanding.  
The maxfd parameter in select() is the largest FD in your input FD_SETs + 1.  
This is because maxfd is used to iterate through the FD_SETs provided.  It has 
nothing to do with other threads calling select() or how many sockets are in 
the system, but the maximum value of any FDs in the current select() call.



Joel


On Jun 23, 2016, at 03:59 AM, lampo  wrote:


hello,
can someone help me with multithread problem ?

we use lwip 1.4.1 in PLC products, and if it live through long time(1 month
for example) testing in industry use,
I will back here to report.

*our problem*
we use multithread select mode in our system, and it "seems" it's ok till
now(1 days passed),
but I see the doc in rawapi.txt,"/Netconn or Socket Api are not reentrant at
the control bolck granularity level/" .
so I really cannot figure out if im doing right thing.

*our application background/restriction*

a, our system is RTOS based , we need 2 TCP clients(separately connecting to
2 TCP servers, i.e., 2 lasers),
1 TCP server(deal with max of 4 remote clients,i.e.,4 modbus clients ), and
1 web server.

b, lwip related thread cannot be in polling mode, for here is already a
polling thread in RTOS and it has "soft real time" requirements.

c, current lwip version is 1.4.1(we are evaluating 2.0.0)

d, we need to send data to tcp servers periodically, 10 ms

*our design/implementation *

3 thread has used 'select' , but the same socket is only closed by the
thread who created it. here is details,

we use 'select' in "user tcp client send thread" ,we first call
'connect',and then call 'select' to determine whether the socket is
connected correctly or not; if some errors detected in connecting or data
sending, we call 'close' to close the socket.
we use 'select' in "user tcp client receive thread", blocked forever
waiting for data, and call 'recvfrom' if data received, if some errors
detected
in this thread,we don't just clost the socket ,but send message to "user tcp
client send thread" and tell it to close.
we use 'select' in "user tcp server thread",listening for incoming requests,
receiving and responding(sending) data.

*our doubt*
1、 ‘select’ can be used in multithread or not? if yes, the first param
maxfdp1 of lwip_select() must be set to the total number of sockets in each
thread?
for example,in our situation, maxfdp1 = 2(clients) + 4(remote clients) +
1(listen socket) in each select?

2、is SYS_ARCH_PROTECT must be used in multithread?

3、if lwip 1.4.1 does not support the multithread select mode, does lwip
2.0.0 supports it?

Thanks a lot !



--
View this message in context: 
http://lwip.100.n7.nabble.com/LwIP-multithread-select-mode-problems-tp26561.html
Sent from the lwip-users mailing list archive at Nabble.com.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users