lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lynx-dev Uniform treatment of fork() and beginthread() calls in ly


From: vtailor
Subject: Re: lynx-dev Uniform treatment of fork() and beginthread() calls in ly
Date: Thu, 25 May 2000 15:10:24 -0400

>     * From: address@hidden
>     * Date: Thu, 25 May 2000 14:54:04 -0400
>   
>I have posted elsewhere on Usenet that there is a simple procedure for
>transforming programs like lynx that use fork() calls to programs that
>use setjmp/longjmp and beginthread().  The basic idea is to setjmp at
>the fork() point and change the end of the child thread to a call on
>beginthread followed by a longjmp to the parent thread.
>
>It seems to me that the lynx code that has calls on fork() could be
>streamlined, and all the alternative code version #ifdefs greatly
>reduced in number if it were rewritten so that both the fork() and the
>beginthread() versions are set up identically, with setjmp() where the
>fork() call was originally, and either beginthread() or a fictitious,
>but similar, beginfork() function at the *bottom* of the child thread,
>followed by the longjmp to the parent thread.
>
>On systems that don't support fork() or beginthread(), it might just be
>possible to use spawn calls followed by longjmp to the parent thread to
>call support programs that replace the child functions, depending on
>just what problems arise in getting things like socket addresses back
>to the calling process.
>
Herewith the thread of the post on comp.programming.threads:

On Tue, 23 May 2000 09:35:12 -0400, John Hickin
 <address@hidden> wrote:
>"Victor Schneider, Ph. D." wrote:
>> 
>> I haven't been reading the professional journals for some time, but
>> somewhere there has to be a theorem proving that fork() under Linux
>> can be simulated effectively by a combination of setjmp() in place
>> of fork(), with the child process executing first, followed by longjmp()
>> at the end of the fork() child process.
>
>In single-threaded code this might be OK. In multi-threaded code you
>will have troubles as setjmp() is unsafe.

I know all about setjmp() being unsafe, but the examples that I have
scrutinized, such as the bash shell and the linux code, don't fall into
this category.  I think you can come up with examples that show you
can't make this work if setjmp or fork is inside a function that doesn't
call the child thread directly, such as the forkshell() function of ash,
but otherwise, it most certainly will work.  All you need to do is to
move the fork() point into the function that descends directly into
the child thread.

; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]