Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Dec 2006 18:00:04 +0000
From:      "Peter Edwards" <peadar@freebsd.org>
To:        freebsd-threads@freebsd.org
Subject:   libpthread problem + possible solution
Message-ID:  <34cb7c840612151000s4a3e1f2dvd71a60d66cf7c4be@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
------=_Part_115896_14548060.1166205604757
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I've a problem when a process uses:
        libpthread
        detached threads
        mixed bound/unbound threads
        suspended threads  (a la pthread_resume_np())

whereby some newly created suspended threads don't get scheduled.
I think I've tracked it down, so if someone could review the
reasoning, I'd be grateful.

Newly launched threads have a "struct pthread" that may be allocated
from a freelist of GCed threads. Apparently, when detached threads
enter the GCed list, they can still have the "active" flag set on
them. Later, this causes problems when this thread is recycled and
resumed, because _thr_setrunnable_unlocked() doesn't add it to a
run queue.

thr_cleanup can be called either from the bound-threads scheduler,
or the unbound scheduler. One callsite clears "active", "needswitchout",
and "lock_switch" to zero before the call. The other callsite just
clears "check_pending". I think these flags are all either bound-thread
or unbound-thread specific, and that there was an unintended
assumption that the thread would remain with the same "boundedness"
after being recycled, which isn't neccessarily the case. (Or another
way - the idea was that there was no need to clear the "active"
flag on a bound thread, as its only used for unbound threads, but
a GCed bound thread might be recycled into an unbound thread)

Given that, it seems correct to clean up the thread the same way
for both cases, and just move that code into thr_cleanup. So, does
the attached patch make sense? I can commit it if someone gives me
the nod. (It definitely fixes my specific problem with threads not
getting scheduled.)

------=_Part_115896_14548060.1166205604757
Content-Type: text/plain; name=pthread.txt; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: base64
X-Attachment-Id: f_evqwn9nn
Content-Disposition: attachment; filename="pthread.txt"

SW5kZXg6IGxpYi9saWJwdGhyZWFkL3RocmVhZC90aHJfa2Vybi5jCj09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09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hlbGQ7IGpvaW5lciB3b24ndCBsZWF2ZS4gKi8K
IAkJaWYgKGpvaW5lci0+a3NlZyA9PSBjdXJrc2UtPmtfa3NlZykgewpAQCAtMTcxNyw5ICsxNzIx
LDYgQEAKIAkJCSAqIHN0YWNrLiAgSXQgaXMgc2FmZSB0byBkbyBnYXJiYWdlIGNvbGxlY3RpbmcK
IAkJCSAqIGhlcmUuCiAJCQkgKi8KLQkJCXRocmVhZC0+YWN0aXZlID0gMDsKLQkJCXRocmVhZC0+
bmVlZF9zd2l0Y2hvdXQgPSAwOwotCQkJdGhyZWFkLT5sb2NrX3N3aXRjaCA9IDA7CiAJCQl0aHJf
Y2xlYW51cChrc2UsIHRocmVhZCk7CiAJCQlyZXR1cm47CiAJCQlicmVhazsK
------=_Part_115896_14548060.1166205604757--



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