Re: event driven paradigm



Matt Kowalczyk wrote:
Ian Collins wrote:

This last paragraph sounds like you are confusing threads and processes.
If you have a multi-process model, then the sockets or pipes with
shared memory may be appropriate, but not with a multi-threaded
application where all threads share the same memory space.

Which are you considering?

I would assume that when I create a pthread, I would pass it a pointer
to an address that contains a structure which defines the work that
thread should perform when it wakes up. This per thread structure would
contain a pointer to the input that the manager receives to avoid
duplicating it. In contrast to your assumption of my "shared memory"
comment, I would not be using shmget() for the shared memory. Is my
understanding of the way threads share memory correct?

It appears to be, all threads within a process share the same address
space, so you scheme would be sound.

To further explain where I'm having difficulty, how can I implement the
manager thread to send a notification a number of threads that input has
been received and they should process it. I would like to avoid
creating a mutex per thread and signal the mutex to wake up each thread
to begin processing the request. Is it possible to create a shared mutex?

A mutex isn't an appropriate primitive to synchronise threads, a
condition variable is a better choice. You could have once CV per
worker and let the manager pick witch thread to wake up, or you could
use one CV for type of workload. With the second approach, any number
of threads could wait for work and the threads could easily change the
type of work they wait for. The master would be able to choose between
waking an single or all threads waiting for a particular workload.

You may be confused by the term shared mutex, which tends to refer to a
specific type mutex shared between processes.

--
Ian Collins.
.



Relevant Pages

  • Re: event driven paradigm
    ... If you have a multi-process model, then the sockets or pipes with ... In contrast to your assumption of my "shared memory" ... manager thread to send a notification a number of threads that input has ... creating a mutex per thread and signal the mutex to wake up each thread ...
    (comp.programming.threads)
  • Re: event driven paradigm
    ... If you have a multi-process model, then the sockets or pipes with ... In contrast to your assumption of my "shared memory" ... manager thread to send a notification a number of threads that input has ... creating a mutex per thread and signal the mutex to wake up each thread ...
    (comp.programming.threads)
  • Re: How to implement synchronous rpc between 2 processes on the same machine.
    ... DOORS(it is a properietry and quite efficient IPC by SUN) ... there to just review this design and provide your much needed inputs. ... Multi-process shared memory impls need to think about misbehaving process.. ... non-blocking timed mutex in there. ...
    (comp.programming.threads)
  • Re: PTHREAD_PROCESS_SHARED on GNU/Linux
    ... a stock Linux kernel won't release the lock on behalf of the ... mutex, so you'd probably have to stop everything and re-initialize the ... shared memory if any process dies unexpectedly. ... If a process dies unexpectedly while holding a mutex, ...
    (comp.programming.threads)
  • Re: Shared-memory between threads and synchronization
    ... In my project i am having different data structures ... process and shared memory should be accessed between different ... co-ordinate activities just through a mutex. ... If the scheduled thread doesnt need the mutexed resource, ...
    (comp.os.linux.development.system)