fork without exec, and pthread_mutex_t used by shared object

前端 未结 1 2034
谎友^
谎友^ 2021-01-27 07:38

I\'m working with a web server project that performs a fork without an exec. The program depends upon OpenSSL, and OpenSSL needs a number of locks (

相关标签:
1条回答
  • 2021-01-27 08:04

    The mutexes won't be valid across the fork unless you put them in shared memory and initialize the mutex attribute with pthread_mutexattr_setpshared set to PTHREAD_PROCESS_SHARED.

    It's not clear if you are forking and then creating threads or creating the threads and then forking. If the latter, then fork will only apply to the thread that calls fork. None of the other threads are created in the new process.

    If you are forking and then threading and the mutexes are meant to only apply to the child process and its threads then just create them after the fork.

    0 讨论(0)
提交回复
热议问题