[OpenSER-Devel] Multi-threading model!

Henning Westerholt henning.westerholt at 1und1.de
Mon Jan 21 10:46:11 UTC 2008


On Monday 21 January 2008, lius wrote:
> Would you tell me the details why OpenSER can't
> use pthread library(multi-threading model). Any
> relationship with data-structure, pkg memery,
> proccess signal?

Hi Lius,

openser uses a multi-process modell, e.g. one master process uses fork() to 
create N child processes handling the requests and do some other maintaince 
tasks. That model don't fit well to a multi-threaded environment.

> So if the multi-threading mode is necessary for
> develping a new module,(such as the module is
> linking a multi-threading model library)how
> can I get them working properly?

If you only need to link against a multi-threaded library, it should work, if 
the library is implemented correctly. But recent experience (e.g. with the 
xmlrpc-c lib) have shown that this is sometimes not true, unfortunally.

Basically you need to protect the state of the thread variables against the 
copy that is done at the fork() call, and restore them to a known state after 
this function call. Otherwise you'll get funny behaviour or dead locks.

Take a look at the 'pthread_atfork' function, this can be used to implement 
fork handlers to implement such a protection/ save initialization. But this 
is not so easy as it seems at a first glance. OpenSER uses a multi-stage 
initialization (modul init vs. child init) process and debugging of 
multi-threaded applications is also really funny. ;-)

If you only need to use a multi-threading library, just try if its work. I 
would also do some extensive testing. If not, complain at the developers of 
this library. 

Based from my experiences i would not suggest to develop a multi-threaded 
openser module, if you can avoid it.

Cheers,

Henning



More information about the Devel mailing list