xiaoxiang781216 commented on PR #16742:
URL: https://github.com/apache/nuttx/pull/16742#issuecomment-3116304244

   > > > > This commit disable interrupts before and after host-APIs, make sure 
that errno is correct.
   > > 
   > > 
   > > the interrupt must be disabled, since many host API can't work well if 
the interrupt happen in side their function.
   > > > i feel this approach is very hard to maintain.
   > > > it's simpler (and probably more efficient) to save/restore errno in 
the "interrupts" instead. what do you think?
   > > 
   > > 
   > > your mean restore errno before enabling interrupt? It doesn't work since 
host main thread manage all nuttx thread and errno will lose if another nuttx 
thread switch in and call some host api which may overwrite the errno value 
before old thread has the chance to retrieve it.
   > 
   > i meant to save/restore in interrupt handlers. as you know, it's a common 
practice for unix to save/restore errno in signal handlers. i don't see any 
reason it doesn't work for sim.
   
   Do you mean save/restore host errno in the interrupt handler? it can't fix 
the problem I describe here, since the problem isn't the signal handler change 
errno. The real  problem is that sim use one host thread with setjmp/longjmp to 
simulate multiple nuttx thread and the race may happen like this:
   
   1. nuttx thread 1 call host function which fail and set errno, but before 
thread 1 read errno
   2. timer signal happen and scheduler switch to nuttx thread 2
   3. nuttx thread 2 may call host function which may fail too and overwrite 
errno
   4. when nuttx thread 1 run again, it read back the wrong errno


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to