[En-Nut-Discussion] MultiThreading

Gervasio Varela gervarela at picandocodigo.com
Thu Mar 1 16:39:23 CET 2007


Hi,

On 01/03/07, MUHAMMAD AZEEM AZAM <muhammadazeemazam786 at yahoo.com> wrote:
>
> when THREAD 1 has
>   NutSleep(0)
>   when its argument is Zero THREAD 1 will give up the CPU.
>
>   when THREAD 2 has
>   NutSleep(125)
>   when its argument is 125ms THREAD 2 will sleep for 125 ms and CPU
> control is transferred to some other THREAD ?


When the thread2 excute NutSleep(125),  it inmediately leaves the CPU  to
other thread (with the same or high priority) that is ready (call it
thread1). Then, 125ms after that, the thread2 gets the READY state, but, if
the thread1 doesn't execute a NutSleep() call, the system has no chance to
give the CPU to thread2. So the thread2 may be sleeping more than 125ms (it
will be sleeping the time taken by the thread1 accomplish it task). This is
what I were talking about when I talk about real time constraints. If you
have such constraints (such as that the code in thread2 may be executed
every 125ms), you must guarantee that the code in thread1 mus take as
maximun 125ms.

In your case, I think that the sleep time is less important than the
frecuency of calls to NutSleep(). Your computing thread (thread1) should
execute NutSleep() frecuently in order to let the networking thread
(thread2) test if there was new request to process.  And the networking
thread should execute NutSleep() as soons as posible, to let the computing
thread do its processing.


-- 
###################################
#    Gervasio Varela                               #
#    gervarela at picandocodigo.com          #
#    http://www.picandocodigo.com          #
###################################



More information about the En-Nut-Discussion mailing list