--mimepart_4caa18667d631_eedd18661017558
Content-Type: text/plain
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

Issue #3436 has been updated by Mark Somerville.

File bug_3436-spawn_the_timer_thread_lazily.patch added

I've attached a patch to fix this.

The thread is now only used when it is required to schedule Ruby threads.hen there is only the main thread, signals are handled immediately in sighandler().

I only have access to Linux boxes. One of the added tests isn't used on other platforms.


----------------------------------------
http://redmine.ruby-lang.org/issues/show/3436

----------------------------------------
http://redmine.ruby-lang.org

--mimepart_4caa18667d631_eedd18661017558
Content-Type: text/x-patch; name=bug_3436-spawn_the_timer_thread_lazily.patch
Content-Transfer-Encoding: Base64
Content-Disposition: attachment; filename=bug_3436-spawn_the_timer_thread_lazily.patch

SW5kZXg6IENoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBD
aGFuZ2VMb2cJKHJldmlzaW9uIDI5NDEwKQorKysgQ2hhbmdlTG9nCSh3b3Jr
aW5nIGNvcHkpCkBAIC0xLDMgKzEsOSBAQAorTW9uIE9jdCAgNCAxODoxNDo0
NyAyMDEwICBNYXJrIFNvbWVydmlsbGUgIDxtYXJrQHNjb3R0aXNoY2xpbWJz
LmNvbT4KKworCSogcHJvY2Vzcy5jLCBzaWduYWwuYywgdGVzdC9ydWJ5L3Rl
c3Rfc2lnbmFsLnJiLAorCSAgdGVzdC90aHJlYWQvdGVzdF90aW1lcl90aHJl
YWQucmI6IHVzZSB0aGUgdGltZXIgdGhyZWFkIG9ubHkgd2hlbgorCSAgbmVl
ZGVkIHRvIHNjaGVkdWxlIFJ1YnkgdGhyZWFkcyBbYnVnICMzNDM2XS4KKwog
TW9uIE9jdCAgNCAxMjo0Mzo0NyAyMDEwICBOb2J1eW9zaGkgTmFrYWRhICA8
bm9idUBydWJ5LWxhbmcub3JnPgogCiAJKiBwYXJzZS55IChyZWdleHApOiBk
cmVnZXhwIGhhcyBsaXRlcmFsIHN0cmluZyBvbmx5IGF0IHRoZSBoZWFkCklu
ZGV4OiB0aHJlYWQuYwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSB0aHJl
YWQuYwkocmV2aXNpb24gMjk0MTApCisrKyB0aHJlYWQuYwkod29ya2luZyBj
b3B5KQpAQCAtNDAyLDcgKzQwMiwyMiBAQAogc3RhdGljIFZBTFVFIHJiX3Ro
cmVhZHB0cl9yYWlzZShyYl90aHJlYWRfdCAqLCBpbnQsIFZBTFVFICopOwog
dm9pZCByYl90aHJlYWRfcmVjeWNsZV9zdGFja19yZWxlYXNlKFZBTFVFICop
OwogCitzdGF0aWMgaW50Cit2bV9saXZpbmdfdGhyZWFkX251bShyYl92bV90
ICp2bSkKK3sKKyAgICByZXR1cm4gdm0tPmxpdmluZ190aHJlYWRzLT5udW1f
ZW50cmllczsKK30KKwogdm9pZAorcmJfdGhyZWFkX3N0YXJ0X3RpbWVyX3Ro
cmVhZCh2b2lkKQoreworICAgIHN5c3RlbV93b3JraW5nID0gMTsKKyAgICBp
ZiAodm1fbGl2aW5nX3RocmVhZF9udW0oR0VUX1ZNKCkpID4gMSkgeworICAg
ICAgICByYl90aHJlYWRfY3JlYXRlX3RpbWVyX3RocmVhZCgpOworICAgIH0K
K30KKwordm9pZAogcnVieV90aHJlYWRfaW5pdF9zdGFjayhyYl90aHJlYWRf
dCAqdGgpCiB7CiAgICAgbmF0aXZlX3RocmVhZF9pbml0X3N0YWNrKHRoKTsK
QEAgLTU2Miw2ICs1NzcsNyBAQAogCXRoLT5zdGF0dXMgPSBUSFJFQURfS0lM
TEVEOwogCXJiX3JhaXNlKHJiX2VUaHJlYWRFcnJvciwgImNhbid0IGNyZWF0
ZSBUaHJlYWQgKCVkKSIsIGVycik7CiAgICAgfQorICAgIHJiX3RocmVhZF9z
dGFydF90aW1lcl90aHJlYWQoKTsKICAgICByZXR1cm4gdGh2YWw7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zf
bHdwcworICBlbmQKK2VuZApJbmRleDogc2lnbmFsLmMKPT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PQotLS0gc2lnbmFsLmMJKHJldmlzaW9uIDI5NDEwKQorKysg
c2lnbmFsLmMJKHdvcmtpbmcgY29weSkKQEAgLTUxOSw2ICs1MTksMTEgQEAK
ICNpZiAhZGVmaW5lZChCU0RfU0lHTkFMKSAmJiAhZGVmaW5lZChQT1NJWF9T
SUdOQUwpCiAgICAgcnVieV9zaWduYWwoc2lnLCBzaWdoYW5kbGVyKTsKICNl
bmRpZgorCisgICAgcmJfdm1fdCAqdm0gPSBHRVRfVk0oKTsKKyAgICBpZiAo
dm0tPnJ1bm5pbmdfdGhyZWFkID09IHZtLT5tYWluX3RocmVhZCkgeworICAg
ICAgICByYl90aHJlYWRwdHJfY2hlY2tfc2lnbmFsKHZtLT5tYWluX3RocmVh
ZCk7CisgICAgfQogfQogCiBpbnQK

--mimepart_4caa18667d631_eedd18661017558--