Sharing heap memory with fork()

前端 未结 5 1160
半阙折子戏
半阙折子戏 2021-02-15 11:53

I am working on implementing a database server in C that will handle requests from multiple clients. In order to do so I am using fork() to handle connections for individual cli

5条回答
  •  囚心锁ツ
    2021-02-15 12:21

    Many popular HTTP servers use fork() to take advantage of multiple processors, Nginx is one of those.

    Threading brings with it an entire set of headaches that I personally like to avoid unless absolutely necessary, like, your program will never be free of crashes caused by multithreading bugs (my experience with other people's threading code).

    Multiprocessing lets you use all the processors on your machine, without implicitly sharing memory between execution threads, by default avoiding all typical, multithreading, endless bugs.

    I like to sleep at night without getting those 2am calls, knowing my web facing, high throughput servers aren't going to crash on me because I failed to see one of dozens of multithreading pitfalls that day.

    There are many cases where shared memory is pain free, such as, if the data in shared memory is read only. You don't have to worry about locks etc.

提交回复
热议问题