Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
setjmp/longjmp with threads
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
sturlamolden  
View profile  
 More options Aug 5 2009, 4:15 am
Newsgroups: comp.lang.c
From: sturlamolden <sturlamol...@yahoo.no>
Date: Wed, 5 Aug 2009 01:15:28 -0700 (PDT)
Local: Wed, Aug 5 2009 4:15 am
Subject: setjmp/longjmp with threads
Here is a short question, forgive me if it shows plain ignorance of C:

- Can I setjmp in one thread and longjmp to the saved jmp_buf in
another?

If you wonder why I would like to do this evilness, the reason is that
Windows has no fork system call. So I wondered if fork could be faked
with non-local goto and threads, obviously with the limitation that no
new address space is created. To my knowledge, setjmp is the only
function apart from fork that returns twice.

Regards,
Sturla


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom St Denis  
View profile  
 More options Aug 5 2009, 6:29 am
Newsgroups: comp.lang.c
From: Tom St Denis <t...@iahu.ca>
Date: Wed, 5 Aug 2009 03:29:56 -0700 (PDT)
Local: Wed, Aug 5 2009 6:29 am
Subject: Re: setjmp/longjmp with threads
On Aug 5, 4:15 am, sturlamolden <sturlamol...@yahoo.no> wrote:

> Here is a short question, forgive me if it shows plain ignorance of C:

> - Can I setjmp in one thread and longjmp to the saved jmp_buf in
> another?

> If you wonder why I would like to do this evilness, the reason is that
> Windows has no fork system call. So I wondered if fork could be faked
> with non-local goto and threads, obviously with the limitation that no
> new address space is created. To my knowledge, setjmp is the only
> function apart from fork that returns twice.

Typically fork() is used as part of executing a new process.  In a
Linux environment if you wanted threads in the same process you'd use
threads (which are a new type of process but that's not the point).

But why not just re-write your program so it does this

if (fork()) {
  patha();

} else {
  pathb();
}

  return 0; /* end of function */

}

That way you can port it to threads in Windows by just calling pathb()
in a thread.

Tom


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexander Bartolich  
View profile  
 More options Aug 5 2009, 9:37 am
Newsgroups: comp.lang.c
From: Alexander Bartolich <alexander.bartol...@gmx.at>
Date: Wed, 5 Aug 2009 13:37:03 +0000 (UTC)
Local: Wed, Aug 5 2009 9:37 am
Subject: Re: setjmp/longjmp with threads

sturlamolden wrote:
> Here is a short question, forgive me if it shows plain ignorance of C:

> - Can I setjmp in one thread and longjmp to the saved jmp_buf in
> another?

This question is platform dependent and cannot be answered within the
context of the C standard.

Anyway, threads usually comprise three things:
- a set of register values
- a stack
- some kind of thread identity within the operating system

The context saved by setjmp typically includes only a set of register
values. Thus calling jmp_buf will use
- the stack of the thread that called setjmp
- the identity of the thread that called setjmp

> If you wonder why I would like to do this evilness, the reason is that
> Windows has no fork system call. So I wondered if fork could be faked
> with non-local goto and threads, obviously with the limitation that no
> new address space is created. To my knowledge, setjmp is the only
> function apart from fork that returns twice.

After fork() all address values are still the same, including the
address of objects on the stack. A new thread on the other hand will
have a new, empty stack at a different location.

After fork() both the parent process and the child process can return
from the function that called fork(). A new thread on the other hand
cannot return beyond CreateThread or pthread_create.

--
Br der, in die Tonne die Freiheit,
Br der, ein Stoppschild davor.
Egal was die Schwarzen Verlangen
Rufen wir: Ja! Brav im Chor.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Thompson  
View profile  
 More options Aug 5 2009, 12:02 pm
Newsgroups: comp.lang.c
From: Keith Thompson <ks...@mib.org>
Date: Wed, 05 Aug 2009 09:02:22 -0700
Local: Wed, Aug 5 2009 12:02 pm
Subject: Re: setjmp/longjmp with threads

sturlamolden <sturlamol...@yahoo.no> writes:
> Here is a short question, forgive me if it shows plain ignorance of C:

> - Can I setjmp in one thread and longjmp to the saved jmp_buf in
> another?

> If you wonder why I would like to do this evilness, the reason is that
> Windows has no fork system call. So I wondered if fork could be faked
> with non-local goto and threads, obviously with the limitation that no
> new address space is created. To my knowledge, setjmp is the only
> function apart from fork that returns twice.

comp.programming.threads might be a good place for this question.

setjmp and longjmp are standard C, but fork and threads are not.

--
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »