Re: event driven paradigm
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Wed, 21 Mar 2007 12:55:33 +1200
Matt Kowalczyk wrote:
Ian Collins wrote:It appears to be, all threads within a process share the same address
I would assume that when I create a pthread, I would pass it a pointerThis 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?
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?
space, so you scheme would be sound.
A mutex isn't an appropriate primitive to synchronise threads, a
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?
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.
.
- Follow-Ups:
- Re: event driven paradigm
- From: Adrian Hawryluk
- Re: event driven paradigm
- From: Matt Kowalczyk
- Re: event driven paradigm
- References:
- event driven paradigm
- From: Matt Kowalczyk
- Re: event driven paradigm
- From: Ian Collins
- Re: event driven paradigm
- From: Matt Kowalczyk
- event driven paradigm
- Prev by Date: Re: event driven paradigm
- Next by Date: Re: System Calls Hang in Multi-Threaded Webcrawler
- Previous by thread: Re: event driven paradigm
- Next by thread: Re: event driven paradigm
- Index(es):
Relevant Pages
|