jeudi 10 juin 2021

Waiting std::condition_variable while forking and forked child process is unable to resume it

I am trying to understand forking with multithreading. So what happens in below scenario ?

  • Application thread has spawned a thread - polling thread
  • Application thread runs fork
  • atpthread_fork handler's pre_fork stops the polling thread using a std::condition_variable. It also waits on a different condition variable to resume the polling
  • atpthread_fork handler's post_fork in child does cv.notify_one for the waiting poll thread and stops the poll thread
  • atpthread_fork handler's post_fork in parent does cv.notify_one for the waiting poll thread and resumes the poll thread

But what happens is, post_fork in child enters an infinite loop where it keeps on waiting. This also doesn't seem to notified the poll thread cv at all.

Why is this happening ?

Aucun commentaire:

Enregistrer un commentaire