hujun260 commented on PR #9497: URL: https://github.com/apache/nuttx/pull/9497#issuecomment-1596350439
> > But select already contain the code to restore: > > https://github.com/apache/nuttx/blob/master/fs/vfs/fs_select.c#L105 > > @xiaoxiang781216 The `fdcheck_protect()` is implemented as > > ``` > /**************************************************************************** > * Name: fdcheck_protect > * > * Description: Obtain the combined value of fd and pid > * > * the return value carries the pid and fd information. > * The original fd information is stored in low bit of val. > * The pid information is stored in high bit of val. > * For ease of understanding, let's give an example where > * the following information is represented in 32-bit binary format > * > * fd 00000000 00000000 00000000 10001010 > * pid 00000000 00000000 00000000 01010101 > * val 00000000 00000000 01010101 10001010 > ``` > > So for example we have 2 pthreads spawned from application `main` task. `main` has pid 50 and open fd 4 while pthread1/2 have pid 40/30 and open fd 5/6. Finally main wants to select based on 3 fds and in normal case it will get max of 4, 5, 6 and finally will pass max_fd + 1 that is 7 to select. While with `fdcheck_protect()` modified fds it will select `main`'s fd 4 as max because of `main` has higher pid value and will pass it +1 to select. Does this makes sense? hi @pkarashchenko In fact, I am using pid instead of tid, and the pid used by the thread is the same as application `main` task. The situation you mentioned will not happen。 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
