Re: Whats your favorite language and why? (LINUX)
- From: "Chris M. Thomasson" <no@xxxxxxxxxxxx>
- Date: Wed, 15 Oct 2008 22:00:54 -0700
"Jon Harrop" <jon@xxxxxxxxxxxxxxxxx> wrote in message news:1YKdnTBMW6ibBWvVnZ2dnUVZ8tzinZ2d@xxxxxxxxx
Ian Collins wrote:Jon Harrop wrote:Chris M. Thomasson wrote:Chris said "intra-process message-passing". How could GC be relevant inI have implemented
efficient distributed intra-process message-passing algorithm on several
architectures that incurs virtually zero-overheads. It does this by
eluding virtually all forms of synchronization. The fast-path for
push/pop is only a couple of instructions, none of which are atomic RMW.
Message-passing can be EXTREMELY efficient,
I agree.
and GC has absolutely nothing to do with it.
I disagree: message passing makes it impossible to determine value
lifetimes statically so lack of a GC makes you resort to worst case
assumptions. So GC makes it easy to write efficient code.
this context?
Messages can and often do convey data in the form of dynamically allocated
data structures. To avoid space leaks, it is essential that the data is
deallocated and that requires the programmer to determine the lifetime of
data passed in messages.
A GC completely automates this process so you can pass data between threads
by reference (i.e. efficiently) without having to do anything at all.
Without a GC, the programmer has a bleak choice between:
1. Just copy everything as Erlang does, effectively giving each thread its
own heap but introducing massive redundancy and performance degradation.
2. Make worst-case assumptions about value lifetimes (i.e. what is the
longest this datum might remain referenceable for?) which are unusually
pessimistic in the case of message passing because it is non-deterministic.
3. Start Greenspunning your own GC, which typically entails reference
counting (a needlessly inefficient form of garbage collector) that keeps
values alive artificially for an unnecessarily long time because it is
unable to traverse the heap accurately.
So the only solutions available in the absence of a GC result in bloat,
inefficiency and are a nightmare to maintain. These problems simply do not
exist if you have a GC.
Not in all scenarios... GC always makes things easier indeed, however, there are situations in which its not necessary, and its use can introduce unneeded overhead indeed. In the realm of intra-thread message passing... Imagine a message type that will only ever be owned by a single thread at a time. A producer creates the message and pushes it onto a queue. Then a consumer pops it; acts on it, and destroys/reuses/pushes the message accordingly. In this case the message is quiescent when the consumer gets it. No GC needed, not even reference counting. Furthermore, lets say that a consumer can reproduce the message... Is a GC needed? No. Think of following pseudo-code:
______________________________________________________
#define PING_PONG 32
#define REUSE_MAX 1024
struct message {
int ping_pong;
message() : ping_pong(0) {}
void reset() {
ping_pong = 0;
}
};
static queue<message> g_queue;
static queue<message> g_reuse;
void producer_threads() {
for (;;) {
message* m = g_reuse.try_pop();
if (! m) {
m = new message;
}
g_queue.push(m);
sleep(3);
}
}
void consumer_threads() {
for (;;) {
message* const m = g_queue.wait_pop();
if (++m->ping_pong > PING_PONG) {
if (g_reuse.count < REUSE_MAX) {
m->reset();
g_queue.push(m);
} else {
delete m;
}
}
g_queue.push();
}
}
______________________________________________________
This is contrived example of course; however, I have used analog of such a scenario in real message passing environment...
.
- Follow-Ups:
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- References:
- Re: Whats your favorite language and why? (LINUX)
- From: RyanMcCoskrie
- Re: Whats your favorite language and why? (LINUX)
- From: toby
- Re: Whats your favorite language and why? (LINUX)
- From: Chris M. Thomasson
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- From: Chris M. Thomasson
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- From: Giancarlo Niccolai
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- From: Giancarlo Niccolai
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- From: Giancarlo Niccolai
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- From: Giancarlo Niccolai
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- From: Chris M. Thomasson
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- From: Ian Collins
- Re: Whats your favorite language and why? (LINUX)
- From: Jon Harrop
- Re: Whats your favorite language and why? (LINUX)
- Prev by Date: Re: Whats your favorite language and why? (LINUX)
- Next by Date: Re: Whats your favorite language and why? (LINUX)
- Previous by thread: Re: Whats your favorite language and why? (LINUX)
- Next by thread: Re: Whats your favorite language and why? (LINUX)
- Index(es):
Relevant Pages
|