9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] libthread API
@ 2010-01-08  9:40 anonymous
  2010-01-09  4:29 ` Gorka Guardiola
  2010-01-09  4:52 ` cinap_lenrek
  0 siblings, 2 replies; 7+ messages in thread
From: anonymous @ 2010-01-08  9:40 UTC (permalink / raw)
  To: 9fans

Why libthread has threadcreate instead of something like fork? With
threadcreate you should make struct to pass more than one argument and
pass a pointer to it.

I also see no problem with recieving different values for each thread.
Memory is shared, but return value is stored in register (accumulator
register for x86) which is not shared.

Maybe it was made for compatibility with Alef? In Alef it is possible
to return mulitply values, maybe they are stored in memory. But there
is rfork with RFMEM flag and it has no problem.

And by the way when libthread should be used and when rfork(RFMEM) is
better?




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] libthread API
  2010-01-08  9:40 [9fans] libthread API anonymous
@ 2010-01-09  4:29 ` Gorka Guardiola
  2010-01-09  4:33   ` erik quanstrom
  2010-01-09  4:52 ` cinap_lenrek
  1 sibling, 1 reply; 7+ messages in thread
From: Gorka Guardiola @ 2010-01-09  4:29 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Fri, Jan 8, 2010 at 10:40 AM, anonymous <aim0shei@lavabit.com> wrote:
> Why libthread has threadcreate instead of something like fork? With

Preemptive vs cooperative.


--
- curiosity sKilled the cat



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] libthread API
  2010-01-09  4:29 ` Gorka Guardiola
@ 2010-01-09  4:33   ` erik quanstrom
  0 siblings, 0 replies; 7+ messages in thread
From: erik quanstrom @ 2010-01-09  4:33 UTC (permalink / raw)
  To: 9fans

On Fri Jan  8 23:31:23 EST 2010, paurea@gmail.com wrote:
> On Fri, Jan 8, 2010 at 10:40 AM, anonymous <aim0shei@lavabit.com> wrote:
> > Why libthread has threadcreate instead of something like fork? With
>
> Preemptive vs cooperative.

i think that misses the point of the question.  the question
could have just as easily been why not proccreate instead of
fork.

- erik



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] libthread API
  2010-01-08  9:40 [9fans] libthread API anonymous
  2010-01-09  4:29 ` Gorka Guardiola
@ 2010-01-09  4:52 ` cinap_lenrek
  2010-01-09  5:33   ` anonymous
  1 sibling, 1 reply; 7+ messages in thread
From: cinap_lenrek @ 2010-01-09  4:52 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 642 bytes --]

the threads and procs that are created by libthread have ther stacks
malloc()ed, so one thread can allocate a structure or buffer on its
stack and pass a pointer to another thread or proc.  when you would do
a rfork(RFMEM) in a libthread program, the stacks would have been
shared by parent and child! libthread does some setjmp/longjmp magic to
switch the stack to the original plan9 stack segment to be able todo
a real rfork when spawning new procs.

also linux clone syscall takes a pointer to the routine running
in a new "thread" for a similar reason. they dont have the concept
of a always copy-on-write stack.

--
cinap

[-- Attachment #2: Type: message/rfc822, Size: 3291 bytes --]

From: anonymous <aim0shei@lavabit.com>
To: 9fans@9fans.net
Subject: [9fans] libthread API
Date: Fri, 8 Jan 2010 12:40:14 +0300
Message-ID: <20100108094014.GA16595@machine>

Why libthread has threadcreate instead of something like fork? With
threadcreate you should make struct to pass more than one argument and
pass a pointer to it.

I also see no problem with recieving different values for each thread.
Memory is shared, but return value is stored in register (accumulator
register for x86) which is not shared.

Maybe it was made for compatibility with Alef? In Alef it is possible
to return mulitply values, maybe they are stored in memory. But there
is rfork with RFMEM flag and it has no problem.

And by the way when libthread should be used and when rfork(RFMEM) is
better?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] libthread API
  2010-01-09  4:52 ` cinap_lenrek
@ 2010-01-09  5:33   ` anonymous
  2010-01-09  5:50     ` cinap_lenrek
  0 siblings, 1 reply; 7+ messages in thread
From: anonymous @ 2010-01-09  5:33 UTC (permalink / raw)
  To: 9fans

Thanks, now I understand. The main question was why threadcreate asks
for function pointer and can't just leave me in my function like rfork.
So it is because we should move local variables out of scope as they
are no more valid cause we have a new completely clear stack.

But when it is better to use rfork with shared memory and when
libthread?




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] libthread API
  2010-01-09  5:33   ` anonymous
@ 2010-01-09  5:50     ` cinap_lenrek
  2010-01-09  5:55       ` Bruce Ellis
  0 siblings, 1 reply; 7+ messages in thread
From: cinap_lenrek @ 2010-01-09  5:50 UTC (permalink / raw)
  To: 9fans

> Thanks, now I understand. The main question was why threadcreate asks
> for function pointer and can't just leave me in my function like rfork.
> So it is because we should move local variables out of scope as they
> are no more valid cause we have a new completely clear stack.
yes.

> But when it is better to use rfork with shared memory and when
> libthread?
depends. but in the majority of cases you want to use libthread because
it also gives you synchronization primitives like channels and has
co-routines called threads wich run cooperatively in a real system
proc.

but nobody forces you to use libthread. you can just use system primitives
like rendezvous, qlocks, pipes and shared memory with rfork.

--
cinap




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9fans] libthread API
  2010-01-09  5:50     ` cinap_lenrek
@ 2010-01-09  5:55       ` Bruce Ellis
  0 siblings, 0 replies; 7+ messages in thread
From: Bruce Ellis @ 2010-01-09  5:55 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

ahh my wise, cold, east german friend.

good answer and fluffy agrees.

brucee

On 1/9/10, cinap_lenrek@gmx.de <cinap_lenrek@gmx.de> wrote:
> > Thanks, now I understand. The main question was why threadcreate asks
> > for function pointer and can't just leave me in my function like rfork.
> > So it is because we should move local variables out of scope as they
> > are no more valid cause we have a new completely clear stack.
> yes.
>
> > But when it is better to use rfork with shared memory and when
> > libthread?
> depends. but in the majority of cases you want to use libthread because
> it also gives you synchronization primitives like channels and has
> co-routines called threads wich run cooperatively in a real system
> proc.
>
> but nobody forces you to use libthread. you can just use system primitives
> like rendezvous, qlocks, pipes and shared memory with rfork.
>
> --
> cinap
>
>
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-01-09  5:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-08  9:40 [9fans] libthread API anonymous
2010-01-09  4:29 ` Gorka Guardiola
2010-01-09  4:33   ` erik quanstrom
2010-01-09  4:52 ` cinap_lenrek
2010-01-09  5:33   ` anonymous
2010-01-09  5:50     ` cinap_lenrek
2010-01-09  5:55       ` Bruce Ellis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).