Re: kernel thread question

B. James Phillippe (bryan@terran.org)
Sun, 30 May 1999 00:44:25 -0700 (PDT)


On Fri, 28 May 1999, Gabor Lenart wrote:

> Hi,
>
> I've got an own kernel thread which do something at every seconds :
...
> But I've got some question :

I'm not an expert (I'm dealing with my own kernel-thread problems :-) but
I'll try to answer some of these as best I can; experts, if I'm wrong,
please correct me.

> * How can I sleep the thread to wake up only by an external effect (like
> calling a function from the other point of kernel, outside the thread)

There are probably a number of ways, but you can try using a shared
semaphore; this way the thread can "down" the semaphore when it wants to
sleep, and some other kernel code can "up" it when it wants to wake the
thread.

You could also try using a shared wait queue and do some variant of
sleep_on in your thread and wake_up from outside the thread.

> * How can I destroy the thread by a function inside the thread

It appears that you simply return your exit value from the thread function,
and that is passed to sys_exit .. do_exit in the normal fashion. I'm not
sure of this; I get lost in the assembly in entry.S.

> * How can I destroy the thread by a function outside the thread

I think the best way to accomplish this is to send a signal to the thread.
I suppose you could also modify some shared variable which would let the
thread know when to return.

I hope this helps.

-bp

--
B. James Phillippe		. bryan@terran.org
Software Engineer, WGT Inc.	. http://www.terran.org/~bryan

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/