Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Jul 1999 10:53:17 -0700 (PDT)
From:      jin@george.lbl.gov
To:        bugs@freebsd.org
Subject:   Re: kern/11984 pthread_kill cannot kill select() threads, etc.
Message-ID:  <199907281753.KAA13231@george.lbl.gov>

next in thread | raw e-mail | index | archive | help
This case is also a summary of cases bin/7587, bin/9162, bin/10092, and
i386/9237. As I pointed out earlier, the thread GC and kill need to be
redesigned to make its logic correct.

I do not know if John Birrell is still working on this project. I have not
heard from him since I talked to him a few years ago. But whoever is in
charge of tracking this problem, I would like work with these people to
make pthread working.

This is critical for FreeBSD being success. We had SMP kernel 3.0-SNAP
developed a few years ago when Linux folks were still working on linux 2.0.x.
However, Linux has had SMP kernel and SMP pthread worked in their 2.2.x
release, but we have not maken a regular pthread (non-SMP) working correctly.

Here is the problem in the current pthread design:

(1) the pthread_kill is lack of a set of flags/status for a thread to be
killed. It simply sets a pthread->interrupted=1 if a thread is in 
PS_*_WAIT states; then for all cases, puts it in a run queue for further
handling.

This is not a right way to kill a thread. Let's look at the most common
and simple case:

dead_loop_for_lookup()
{
    while(1)	{
	if (have_thing_to_do)
		do_it();
	else	sleep(1);
    }
}

main(...)
{
...
	pid = pthread(..., dead_loop_for_lookup, ...);
	pthread_kill(pid, 0);
pthread_exit(0);
}

The function -- dead_loop_for_lookup -- will be wake up once when
pthread_kill() has been executed, back to sleep if nothing to do,
and dies in the loop forever.


(2) GC too does dead-loop. The GC checks on attr.flags & PTHREAD_DETACHED
and only on this flag for destory a thread. I doubt it is right approch.
Any thread can be detached immediately when it is created. There is no
logic to destory a detached thread.
GC supposes to destory EXITING and KILLING/KILLED threads. If we replace
the condition with these flags instead of PTHREAD_DETACHED, most above
problem will be solved, except missing function.

I have tested to replace PTHREAD_DETACHED by EXITING for thread destory,
and everything works fine in pthread_exit(0), but not kill since we do
not have such flags. Below is existing flags:

#define PTHREAD_FLAGS_PRIVATE   0x0001
#define PTHREAD_EXITING         0x0002
#define PTHREAD_FLAGS_QUEUED    0x0004  /* in queue (qe is used) */
#define PTHREAD_FLAGS_TRACE     0x0008

Shall we add PTHREAD_KILLING and PTHREAD_KILLED flags and tune the current
thread-destory condition? or is there other solution?

	-Jin



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907281753.KAA13231>