Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9f2e82

Browse files
committed
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
to avoid hanging in cleanup().
1 parent 0297512 commit f9f2e82

5 files changed

Lines changed: 252 additions & 91 deletions

File tree

Include/pythread.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
void init_thread _P((void));
1111
int start_new_thread _P((void (*)(void *), void *));
1212
void exit_thread _P((void));
13+
void _exit_thread _P((void));
1314

1415
typedef void *type_lock;
1516

@@ -20,7 +21,15 @@ int acquire_lock _P((type_lock, int));
2021
#define NOWAIT_LOCK 0
2122
void release_lock _P((type_lock));
2223

24+
typedef void *type_sema;
25+
26+
type_sema allocate_sema _P((int));
27+
void free_sema _P((type_sema));
28+
void down_sema _P((type_sema));
29+
void up_sema _P((type_sema));
30+
2331
void exit_prog _P((int));
32+
void _exit_prog _P((int));
2433

2534
#undef _P
2635

Include/thread.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
void init_thread _P((void));
1111
int start_new_thread _P((void (*)(void *), void *));
1212
void exit_thread _P((void));
13+
void _exit_thread _P((void));
1314

1415
typedef void *type_lock;
1516

@@ -20,7 +21,15 @@ int acquire_lock _P((type_lock, int));
2021
#define NOWAIT_LOCK 0
2122
void release_lock _P((type_lock));
2223

24+
typedef void *type_sema;
25+
26+
type_sema allocate_sema _P((int));
27+
void free_sema _P((type_sema));
28+
void down_sema _P((type_sema));
29+
void up_sema _P((type_sema));
30+
2331
void exit_prog _P((int));
32+
void _exit_prog _P((int));
2433

2534
#undef _P
2635

Modules/threadmodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3131

3232
#include "thread.h"
3333

34+
int threads_started = 0;
35+
3436
object *ThreadError;
3537

3638

@@ -177,6 +179,8 @@ t_bootstrap(args_raw)
177179
object *args = (object *) args_raw;
178180
object *func, *arg, *res;
179181

182+
threads_started++;
183+
180184
restore_thread((void *)NULL);
181185
func = gettupleitem(args, 0);
182186
arg = gettupleitem(args, 1);
@@ -230,7 +234,7 @@ thread_exit_prog(self, args)
230234
int sts;
231235
if (!getargs(args, "i", &sts))
232236
return NULL;
233-
goaway(sts);
237+
goaway(sts); /* Calls exit_prog(sts) or _exit_prog(sts) */
234238
for (;;) { } /* Should not be reached */
235239
}
236240

Python/pythonrun.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ fatal(msg)
361361

362362
/* Clean up and exit */
363363

364+
#ifdef USE_THREAD
365+
extern int threads_started;
366+
#endif
367+
364368
void
365369
goaway(sts)
366370
int sts;
@@ -375,7 +379,10 @@ goaway(sts)
375379

376380
(void) save_thread();
377381
donecalls();
378-
exit_prog(sts);
382+
if (threads_started)
383+
_exit_prog(sts);
384+
else
385+
exit_prog(sts);
379386

380387
#else /* USE_THREAD */
381388

0 commit comments

Comments
 (0)