lwip-devel
[Top][All Lists]
Advanced

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

Re: [lwip-devel] Problem with netconn_write()


From: Peter Graf
Subject: Re: [lwip-devel] Problem with netconn_write()
Date: Thu, 19 Aug 2004 10:46:35 +0200
User-agent: Mozilla Thunderbird 0.5 (Windows/20040502)

Hi Tony,

I've just run into a problem with netconn_write() and its interaction with 
sent_tcp().

Having sped up my execution by enabling the CPU cache (this is new hardware), I 
started finding the underlying OS would occasionally hit a fatal error due to 
trying to signal a deleted semaphore. This was always in sent_tcp(), in the 
following code:

 if (conn != NULL && conn->sem != SYS_SEM_NULL) {
   sys_sem_signal(conn->sem);
 }

The thread was being pre-empted after testing conn->sem, so that by the time my 
implementation of sys_sem_signal() called the OS, another thread had already come 
along and deleted the semaphore.

I deduced that the culprit was netconn_write() in api_msg.c: it creates a 
semaphore on entry, if it doesn't already exist, whic is fair enough. However, 
it deletes it again just before it exits. So for every write a semaphore is 
getting created and then deleted. Surely it would be better to leave the 
semaphore in existence, and  free it in netconn_close().
Years ago, I ran into a timinig-dependent problem with netconn_write(), which has probably the same roots. IIRC I came to the same conclusion, the semaphore should exist until netconn_close().

In any case, assuming sys_sem_signal() and sys_sem_free() can't block, there 
should perhaps be some exclusion to make sure that a test of conn->sem and its 
subsequent use are indivisble, for semaphores that can be dynamically deleted.
A usual implementation of sys_sem_signal() is likely to leave through the OSes scheduler, switching to a different task, so I guess the check and the call can not be made indivisible by a simple solution like the "lightweight protection" here (which disables task-switching). I hesitate to propose a more complicated solution. The best would be to remove the need for the check.

All the best
Peter







reply via email to

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