You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/09/12 15:46:10 UTC
[GitHub] bhavinthaker commented on issue #3946: When predicting, does mxnet provide thread-safe interface?
bhavinthaker commented on issue #3946: When predicting, does mxnet provide thread-safe interface?
URL: https://github.com/apache/incubator-mxnet/issues/3946#issuecomment-328894574
Good points made by piiswrong@ and leopd@.
Based on my experience of using fork() over many years, I would say that calling fork() from a Multi-Threaded process is typically NOT recommended. If you do, you will need to understand the details in how it works to make correct use of it. A few caveats on the use of fork() are:
1. The behavior of fork() can vary across operating systems. For example, Solaris has fork-one and fork-all model, whereas Linux has fork-one model. The fork-one model duplicates only the calling thread whereas the fork-all model duplicates all the calling threads.
2. The fork-one model can leave mutexes in bad state in the called thread. See excellent description of the problems in the classic book on Linux Programming Interface [2].
3. A good summary of the problem is here: [3]
4. More problems are described here: [4]. For example, you need to ensure that Close-on-exec flag is set for file-descriptors [depends on whether the programming language does it for you, C does not], otherwise two processes will have reference to the same file and close() from one process will NOT actually close the file since the file is also referenced from the other process.
5. Long discussion on why fork without exec is dangerous in large programs [5]. I always used exec() after a fork() and set the Close-on-exec() for file-descriptions when I have called fork() from a MT process.
References:
[1] fork-one and fork-all model: https://docs.oracle.com/cd/E19683-01/806-6867/gen-1/index.html
[2] The Linux Programming Interface: A Linux and UNIX System Programming Handbook
By Michael Kerrisk: https://books.google.com/books?id=Ps2SH727eCIC&pg=PA686&lpg=PA686&dq=fork+but+no+exec+mutex&source=bl&ots=kMBgx2BVwb&sig=PI74pt3fvO8gHKLLUaIUrr_shy8&hl=en&sa=X&ved=0ahUKEwjTu8qn75_WAhVJ7GMKHb46BQIQ6AEIOjAH#v=onepage&q=fork%20but%20no%20exec%20mutex&f=false
[3] https://thorstenball.com/blog/2014/10/13/why-threads-cant-fork/
[4] http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them
[5] https://news.ycombinator.com/item?id=12302539
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services