public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* Re: [ECOS] Threads that end
@ 2000-06-29 23:45 jens.ohlund
  2000-06-30  0:13 ` Jonathan Larmour
  0 siblings, 1 reply; 4+ messages in thread
From: jens.ohlund @ 2000-06-29 23:45 UTC (permalink / raw)
  To: ecos-discuss

Hi !

Thanks for the confirmation. Now, how do I detect from another thread that one thread is "finished" so i can delete it ?
I don't have any locks in those two threads, so hanging on a resurce doesn't happen. I just want my memory back :).

But, just an idea, your giving a stack to the thread to run in. If the thread allocates any local variables, the are on the threads
stack ?
Then I would be able to just kill the thread and then create a new thread, with the old "stack" as parameter to the cy_thread_create
?

yours
Jens





ecos-discuss-owner@sourceware.cygnus.com
2000-06-29 18:43


To:   jens.ohlund@secrc.abb.se
cc:   ecos-discuss@sourceware.cygnus.com, Robert Erskine <roberte@redhat.co.uk>
Subject:  Re: [ECOS] Threads that end

Security Level:?         Internal


jens.ohlund@secrc.abb.se wrote:
>
> Hi !
>
> I wonder what happens when a thread leaves the method it was given to run when created.
> Does it just "run away" or does it "die" (suspend) or what ?
>
[snip]
> Does the thread leaves the method, frees up resources and turns to a suspend mode ?

It doesn't free up resources, but it does suspend.

> If it does, does that mean I have to delete it afterwards to make it disaper in the scheduler ?

Indeed so, use cyg_thread_delete() for that. See

http://sourceware.cygnus.com/ecos/docs-latest/ref/ecos-ref.9.html#pgfId=1088577
[ although Robert take note: the HTML fonts in this bit are all wrong ]

In summary, cyg_thread_kill() sends a kill message to a thread, causing it
to wake up and return an error message from whatever it's locked in the
kernel doing. cyg_thread_delete() deregisters the thread from the
scheduler, freeing up the thread resources (although not any resources
allocated by the thread itself, if you see what I mean).

Jifl
--
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault





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

* Re: [ECOS] Threads that end
  2000-06-29 23:45 [ECOS] Threads that end jens.ohlund
@ 2000-06-30  0:13 ` Jonathan Larmour
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Larmour @ 2000-06-30  0:13 UTC (permalink / raw)
  To: jens.ohlund; +Cc: ecos-discuss

jens.ohlund@secrc.abb.se wrote:
> 
> Hi !
> 
> Thanks for the confirmation. Now, how do I detect from another thread that one thread is "finished" so i can delete it ?

Internally the kernel tracks the state of the thread, and knows that it has
exited, but that type of implementation-dependent state information is not
wise to export in the official API. Really you should use some sort of
message passing primitive to indicate which threads have finished so you
can delete them.

A message box is probably the best primitive. Just before a thread leaves
its entry function, simply do:

cyg_mbox_put( mbox, cyg_thread_self() );

Then wherever it is you want to manage the deletion of threads, you do
something like:

cyg_handle_t th;
th = cyg_mbox_get( mbox );
while (!cyg_thread_delete( th )
  cyg_thread_delay(1);

> I don't have any locks in those two threads, so hanging on a resurce doesn't happen. I just want my memory back :).
> 
> But, just an idea, your giving a stack to the thread to run in. If the thread allocates any local variables, the are on the threads
> stack ?

Yes.

> Then I would be able to just kill the thread and then create a new thread, with the old "stack" as parameter to the cy_thread_create
> ?

Yes, but be sure to use cyg_thread_delete, not cyg_thread_kill if you are
doing this.

Jifl
-- 
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault

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

* Re: [ECOS] Threads that end
  2000-06-28 23:30 jens.ohlund
@ 2000-06-29  9:43 ` Jonathan Larmour
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Larmour @ 2000-06-29  9:43 UTC (permalink / raw)
  To: jens.ohlund; +Cc: ecos-discuss, Robert Erskine

jens.ohlund@secrc.abb.se wrote:
> 
> Hi !
> 
> I wonder what happens when a thread leaves the method it was given to run when created.
> Does it just "run away" or does it "die" (suspend) or what ?
> 
[snip]
> Does the thread leaves the method, frees up resources and turns to a suspend mode ?

It doesn't free up resources, but it does suspend.

> If it does, does that mean I have to delete it afterwards to make it disaper in the scheduler ?

Indeed so, use cyg_thread_delete() for that. See

http://sourceware.cygnus.com/ecos/docs-latest/ref/ecos-ref.9.html#pgfId=1088577
[ although Robert take note: the HTML fonts in this bit are all wrong ]

In summary, cyg_thread_kill() sends a kill message to a thread, causing it
to wake up and return an error message from whatever it's locked in the
kernel doing. cyg_thread_delete() deregisters the thread from the
scheduler, freeing up the thread resources (although not any resources
allocated by the thread itself, if you see what I mean).

Jifl
-- 
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault

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

* [ECOS] Threads that end
@ 2000-06-28 23:30 jens.ohlund
  2000-06-29  9:43 ` Jonathan Larmour
  0 siblings, 1 reply; 4+ messages in thread
From: jens.ohlund @ 2000-06-28 23:30 UTC (permalink / raw)
  To: ecos-discuss

Hi !

I wonder what happens when a thread leaves the method it was given to run when created.
Does it just "run away" or does it "die" (suspend) or what ?

I have ported simpleRTJ to the AEB-1 and it communicates through a serial port.
So I got three threads, two taking care of sending and receiving data over the serial port.
The last one is a "guardian", it takes the data from the serialport, divides it into data that are going to the javaapplication
or to the guardian as servicedata.
The user connects to the jvm from pc and downloads the java code to the card. After that he can start the execution of the jvm and
that means that a thread is created which runs the jvm. After that I can stop the thread and restart the jvm (within a while = the
thread still exist), pause it (thread.suspend). But i'd like to have a Reset as well, and with that I mean I'd like to make the
thread
leave the jvm code (works) and leave the method it was executing (so resources is returned).

Does the thread leaves the method, frees up resources and turns to a suspend mode ?
If it does, does that mean I have to delete it afterwards to make it disaper in the scheduler ?

yours
Jens Ohlund

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

end of thread, other threads:[~2000-06-30  0:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-29 23:45 [ECOS] Threads that end jens.ohlund
2000-06-30  0:13 ` Jonathan Larmour
  -- strict thread matches above, loose matches on Subject: below --
2000-06-28 23:30 jens.ohlund
2000-06-29  9:43 ` Jonathan Larmour

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 read-only IMAP folder(s) and NNTP newsgroup(s).