[nanomsg] Re: nanomsg rewrite - new API

  • From: "Martin \"eto\" Misuth" <et.code@xxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Thu, 15 Dec 2016 13:31:52 +0100

On Wed, 14 Dec 2016 07:33:46 -0800
"Garrett D'Amore" <garrett@xxxxxxxxxx> wrote:

Some of the details are a little bit incorrect, and also linux specific
(clone() is used to create both whole processes and threads or lightweight
processes.)  However the conclusions remain the same.

Roger. After sending email, I re-read clone() man page really slowly and
thoroughly, and realized, I did great mistake. Sorry for concluding to soon.
Seems like clone() is swiss army knife of process duplication, usable for
everything from threads up to fork, and is realy very, very complex call.
And combination of clone() call parameters can create very strange children.
I will be more careful next time.

Most of the daemons you see probably have just used fork() to create copies
of themselves.  This is a common practice, especially amongst older
software that runs on systems that predate the existence of pthreads.  Most
webservers (Apache, etc.) use this strategy for example.  These are not
LWPs but real processes; they just didn’t do exec() after calling fork().

Well, I am pretty sure those are not simple forked children, because that is the
paradigm I use myself.

...
At any rate, traditional tools like ps probably won’t be able to observe
threads or LWPs with the usual options.  Some of them may have options to
include the LWPs in their output, but you usually have to ask for this
specifically.

To see "them" I used: ps -T -p $pid, top -H, and "Show custom thread names" in
htop. Anyway ...

I have complete confidence that the use of threads by nanomsg and nng will
not affect you.  I’d say you can effectively ignore the presence of
pthreads (except that for some ugly technical reasons, nanomsg and nng do
not support calling back into the library in the child of a fork() unless
exec() is called in the child first.  I think its unlikely you’re doing
that based on what you’ve told me already.)

This all what I wanted to know.

Regarding fork() behaviour, I personally either fork() right away (because there
is same problem with forking and having eventloop engine like ev already
spinning (this can be overcome but i picked simpler solution)), or
fork()/exec() into "worker", so this should no pose problem either.

Thank you very much, for your time. 

  eto

Other related posts: