tags:

views:

95

answers:

2

Parent process preforked a number of process and each preforked process created number of threads (thread pools). All the thread in the same address space can share the data and can use the different synchronization techniques for critical sections. I want to know how to synchronized between threads which are from different address space. My initial thought (I may be wrong) is to use shared memory and uses semaphore for synchronization. This design will increase two much use of semaphores/mutex.

Is there a better design to overcome the problem?. I know the apache 2.0 uses the hybrid mulitprocess and multithreaded server design. It will be helpful if i have some skeleton code idea for hybrid approach. I am more focusing on scalability and robustness.

+1  A: 

I generally stick to one or another -- fork, and use inter-process IPC (shared memory, pipes, sockets, etc.), or threads, and communicate via in-memory structures. Unless mixing forking and threads is buying you something, I'd recommend picking one and running with it.

LnxPrgr3
+1  A: 

In general, if you need synchronisation between two threads that don't share an address space, it's because they're working on the same region of the same file.

flock() (and the finer-grained variant in fcntl()) is there to solve that problem.

If it's because they're working on the same database table, then just use your DBMS's transactions.

caf