1 |
hattya 12/06/02 07:57:21 |
2 |
|
3 |
Added: gauche-0.9.3.3-gauche.threads.diff |
4 |
Removed: gauche-0.9.3.2-Makefile.diff |
5 |
Log: |
6 |
new upstream release. |
7 |
|
8 |
(Portage version: 2.1.10.49/cvs/Linux i686) |
9 |
|
10 |
Revision Changes Path |
11 |
1.1 dev-scheme/gauche/files/gauche-0.9.3.3-gauche.threads.diff |
12 |
|
13 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-scheme/gauche/files/gauche-0.9.3.3-gauche.threads.diff?rev=1.1&view=markup |
14 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-scheme/gauche/files/gauche-0.9.3.3-gauche.threads.diff?rev=1.1&content-type=text/plain |
15 |
|
16 |
Index: gauche-0.9.3.3-gauche.threads.diff |
17 |
=================================================================== |
18 |
commit 60d82dd56c15a533562cf28111af5d3365d5d354 |
19 |
Author: Shiro Kawai <shiro@×××.org> |
20 |
Date: Thu May 31 15:23:22 2012 -1000 |
21 |
|
22 |
Fixed thread-terminate! bug that SEGVs when applied on non-running threads |
23 |
|
24 |
--- a/ext/threads/test.scm |
25 |
+++ b/ext/threads/test.scm |
26 |
@@ -100,6 +100,18 @@ |
27 |
(thread-terminate! t1) |
28 |
(thread-join! t1)))) |
29 |
|
30 |
+;; this SEGVs on 0.9.3.3. test code from @cryks. |
31 |
+(test* "thread termination before running" 'terminated |
32 |
+ (let1 t1 (make-thread (^[] #f)) |
33 |
+ (thread-terminate! t1) |
34 |
+ (thread-state t1))) |
35 |
+ |
36 |
+(test* "thread termination while being stopped" 'terminated |
37 |
+ (let1 t1 (thread-start! (make-thread (^[] (let loop () (loop))))) |
38 |
+ (thread-stop! t1) |
39 |
+ (thread-terminate! t1) |
40 |
+ (thread-state t1))) |
41 |
+ |
42 |
;;--------------------------------------------------------------------- |
43 |
(test-section "thread and error") |
44 |
|
45 |
--- a/ext/threads/threads.c |
46 |
+++ b/ext/threads/threads.c |
47 |
@@ -432,36 +432,41 @@ ScmObj Scm_ThreadTerminate(ScmVM *target) |
48 |
} |
49 |
|
50 |
(void)SCM_INTERNAL_MUTEX_LOCK(target->vmlock); |
51 |
- do { |
52 |
- /* This ensures only the first call of thread-terminate! on a thread |
53 |
- is in effect. */ |
54 |
- if (target->canceller == NULL) { |
55 |
- target->canceller = vm; |
56 |
- |
57 |
- /* First try */ |
58 |
- target->stopRequest = SCM_VM_REQUEST_TERMINATE; |
59 |
- target->attentionRequest = TRUE; |
60 |
- if (wait_for_termination(target)) break; |
61 |
- |
62 |
- /* Second try */ |
63 |
+ if (target->state == SCM_VM_RUNNABLE || target->state == SCM_VM_STOPPED) { |
64 |
+ do { |
65 |
+ /* This ensures only the first call of thread-terminate! on a |
66 |
+ thread is in effect. */ |
67 |
+ if (target->canceller == NULL) { |
68 |
+ target->canceller = vm; |
69 |
+ |
70 |
+ /* First try */ |
71 |
+ target->stopRequest = SCM_VM_REQUEST_TERMINATE; |
72 |
+ target->attentionRequest = TRUE; |
73 |
+ if (wait_for_termination(target)) break; |
74 |
+ |
75 |
+ /* Second try */ |
76 |
+ SCM_ASSERT(target->thread); |
77 |
#if defined(GAUCHE_USE_PTHREADS) |
78 |
# if defined(GAUCHE_PTHREAD_SIGNAL) |
79 |
- pthread_kill(target->thread, GAUCHE_PTHREAD_SIGNAL); |
80 |
+ pthread_kill(target->thread, GAUCHE_PTHREAD_SIGNAL); |
81 |
# endif /*defined(GAUCHE_PTHREAD_SIGNAL)*/ |
82 |
#elif defined(GAUCHE_USE_WTHREADS) |
83 |
- /* TODO: implement signal mechanism using an event */ |
84 |
+ /* TODO: implement signal mechanism using an event */ |
85 |
#endif /* defined(GAUCHE_USE_WTHREADS) */ |
86 |
- if (wait_for_termination(target)) break; |
87 |
+ if (wait_for_termination(target)) break; |
88 |
|
89 |
- /* Last resort */ |
90 |
- thread_cleanup_inner(target); |
91 |
+ /* Last resort */ |
92 |
+ thread_cleanup_inner(target); |
93 |
#if defined(GAUCHE_USE_PTHREADS) |
94 |
- pthread_cancel(target->thread); |
95 |
+ pthread_cancel(target->thread); |
96 |
#elif defined(GAUCHE_USE_WTHREADS) |
97 |
- TerminateThread(target->thread, 0); |
98 |
+ TerminateThread(target->thread, 0); |
99 |
#endif |
100 |
- } |
101 |
- } while (0); |
102 |
+ } |
103 |
+ } while (0); |
104 |
+ } |
105 |
+ /* target either is terminated or hasn't been run */ |
106 |
+ target->state = SCM_VM_TERMINATED; |
107 |
(void)SCM_INTERNAL_MUTEX_UNLOCK(target->vmlock); |
108 |
return SCM_UNDEFINED; |
109 |
} |
110 |
--- a/test/control.scm |
111 |
+++ b/test/control.scm |
112 |
@@ -72,7 +72,7 @@ |
113 |
;; |
114 |
|
115 |
(cond-expand |
116 |
- [gauche.sys.pthreads |
117 |
+ [gauche.sys.threads |
118 |
(test-section "control.thread-pool") |
119 |
(use control.thread-pool) |
120 |
(test-module 'control.thread-pool) |
121 |
@@ -173,7 +173,15 @@ |
122 |
(let1 xjob (add-job! pool work) |
123 |
(terminate-all! pool :force-timeout 0.05) |
124 |
(job-status xjob)))) |
125 |
- ] |
126 |
+ |
127 |
+ ;; This SEGVs on 0.9.3.3 (test code by @cryks) |
128 |
+ (test* "thread pool termination" 'terminated |
129 |
+ (let ([t (thread-start! (make-thread (cut undefined)))] |
130 |
+ [pool (make-thread-pool 10)]) |
131 |
+ (terminate-all! pool) |
132 |
+ (thread-terminate! t) |
133 |
+ (thread-state t))) |
134 |
+ ] ; gauche.sys.pthreads |
135 |
[else]) |
136 |
|
137 |
(test-end) |