This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How to "atomize" the end of a thread...


Fabrice Gautier <Fabrice_Gautier@sdesigns.com> writes:

> Hi,
> 
> Let's say i have a thread, past a certain point in this thread I want to
> lock the scheduler so that the thread will go to the end uninterrupted (I
> want to atomize the last few lines of this thread). 
> 
> I don't want to do :
> void thread1 ( int arg)
> {
>   ...
>   cyg_sched_lock();
>   atomic_function();
>   cyg_sched_unlock();
> } 
> 
> because I really want the thread to really return end before any other do
> anything.
> 
> What happen if I do that with 
> 
> void thread1 ( int arg)
> {
>   ...
>   cyg_sched_lock();
>   atomic_function();
> } 
>  ?
> 
> You may have guessed that i'm trying to do a very bad thing. In this case i
> want to free the stack used by the thread at the end of the thread, and this
> would go bad if  someone were reusing this memory before the last function
> returned and the thread was deleted from the scheduler.

You could reclaim thread1's resources from another thread after making sure that
thread1 has entered the EXITED state, so you don't need the atomic termination
of thread1.

Robin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]