Re: Whats your favorite language and why? (LINUX)




"Jon Harrop" <jon@xxxxxxxxxxxxxxxxx> wrote in message news:1YKdnTBMW6ibBWvVnZ2dnUVZ8tzinZ2d@xxxxxxxxx
Ian Collins wrote:
Jon Harrop wrote:
Chris M. Thomasson wrote:
I 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.

Chris said "intra-process message-passing". How could GC be relevant in
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...

.



Relevant Pages

  • Re: back once again...
    ... reference to type ... a, signed char ... int dycObjectP(dyt obj); ... void dycBeginClass; ...
    (comp.lang.misc)
  • [PATCH 12/15] dm: add exports
    ... Export core device-mapper functions for manipulating mapped devices ... void dm_get ... struct dm_target; ... * Drop the reference with dm_put when you finish with the object. ...
    (Linux-Kernel)
  • Re: Strong thread safety and lock free?
    ... you definitely can pack pointer and counter into single word. ... No, there is no emulation of locks, just 2 reference counters ... Automatic alignment but typically no explicit alignment required ... static void debuglog(const char* fmt, ...
    (comp.programming.threads)
  • Re: Whats your favorite language and why? (LINUX)
    ... architectures that incurs virtually zero-overheads. ... by reference without having to do anything at all. ... Make worst-case assumptions about value lifetimes (i.e. what is the ... counting (a needlessly inefficient form of garbage collector) that keeps ...
    (comp.programming)
  • Re: C to Java migration - how to cope with passing by value only?
    ... > void Foo(Color cl, JButton bn) { ... In C++, with reference parameters, I suspect you're not really doing quite ... public JButton button; ...
    (comp.lang.java.programmer)