12.27

    1. FILE *fpin, *fpout;
    2. fpin = fdopen(sockfd, "r");
    3. fpout = fdopen(sockfd, "w");
    4. // read and write
    5. fclose(fpin);
    6. fclose(fpout);

    ref: 10.11

    fdopen open 2 stream on same sockfd, fdclose will close sockfd under stream.
    if you call fclose 2 stream on the same sockfd, the second fclose will fail.

    image one thread execute code and open 2 stream on fd N. after execution of line
    fclose(fpin);, program create another thread and execute the same code.

    but

    after fclose(fpin); in thread 1, fd N is reusable again. assume thread 2 use
    the fd N again: thread 1 execute line fclose(fpout); close the fd that thread
    2 is using. it’ll cause something unpredicted.