[Ns-developers] [ns3] a synchronous socket/posix API

Mathieu Lacage mathieu.lacage at sophia.inria.fr
Fri Apr 4 18:55:12 PDT 2008


On Fri, 2008-04-04 at 15:50 -0700, Sam Jansen wrote:
> Looks like it is based on makecontext et. al., which are now
> deprecated POSIX functions (see
> http://www.opengroup.org/onlinepubs/000095399/functions/makecontext.html
> ). These functions allow one to save and switch stack space, which
> allows you to implement co-operative multitasking in user space.

If they are deprecated, do they have a proposed replacement ?

> Practically, newer versions of glibc on Linux have an implementation
> of this, at least for i386 and amd64. It appeared somewhen in the
> 2.3.x series of glibc I think. FreeBSD and Darwin also have
> implementations in their libc implementations as far as I know. I
> don't know how wide ranging support for this is, when I looked into
> these a few months ago I found support lacking in some areas.

The osx ucontext-based version seemed to work fine when I tested it a
while ago. I also wrote a ppc osx and an x86 linux assembly version 2
years ago I think but since none of these seemed to provide any extra
feature on top of this basic makecontext/swapcontext implementation, I
got rid of them.

> 
> It might be useful to have a threads based implementation and fall
> back to that when these aren't available. I've done this with threads
> in the past which isn't too hard, but I found efficiency to be lacking
> a bit. Do you test performance at all Mathieu?

No, I have never tested the performance of this approach, although, yes,
performance is the classic argument in favor of coroutines since they do
not require an extra syscall for each context switch. I expect that, in
our case, where the user code does not do much cpu-intensive tasks,
switching time will dominate so, coroutines will most likely be a
serious performance gain. 

However, I have to confess that performance is not the main reason I
picked this approach: I found it easier to implement it that way because
I did not have to worry about locking. 

Mathieu



More information about the Ns-developers mailing list