In a multithread program, thread A wait for a message from a af_netlink socket with the interface select first. Then thread B calls close to this socket. In this situation, thread A would not be woken up forever. This problem may be caused by missing call to the funtion release_sock to the socket in the funthon netlink_release. Can anyone fix this problem?
The situation is as follows: Thread A Thread B fd = socket(AF_NETLINK, NETLINK_GENERIC); ret = bind(fd) select(fd) close(fd) After close(fd), thread A would not be woken up.
Are you sure? netlink_release() is supposed to be called when the last reference of socket fd is gone, since Thread A is still select()'ing, how could it be released?
Also, you misunderstand release_sock(), it is paired with lock_sock(). sock_release() is called when the last fd reference is gone and it is independent to socket type: static int sock_close(struct inode *inode, struct file *filp) { sock_release(SOCKET_I(inode)); return 0; }