60 likes | 196 Vues
This guide explores the `select()` function in C, a crucial tool for I/O multiplexing that allows a program to monitor multiple file descriptors. You will learn how to use `select()` to wait for events on file descriptors including reading, writing, and error notifications. We will discuss the parameters such as `nfds`, `readfds`, `writefds`, and `timeout`, providing example code snippets for clarity. Additionally, we will examine how to use pipes for inter-thread communication, enhancing your understanding of concurrent programming in C.
E N D
MP7 • Any questions?
select() • int select( int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict errorfds, struct timeval *restrict timeout);
select() Return Value: Number of fds ready to be acted upon. • int select( int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict errorfds, struct timeval *restrict timeout);
select() Return Value: Number of fds ready to be acted upon. • int select( int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict errorfds, struct timeval *restrict timeout); nfds: max(fds) + 1 or FD_SETSIZE
Coding • In ds10, we’ll look at using: • pipe() to communicate between threads • select() to do I/O multiplexing • As always: ds/ds10/1.c ds/ds10/2.c