Skip to content

Commit 0b83200

Browse files
committed
stop using pthread_cancel()
1 parent 39f3ade commit 0b83200

File tree

3 files changed

+3
-59
lines changed

3 files changed

+3
-59
lines changed

core/loop.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ void uwsgi_setup_thread_req(long core_id, struct wsgi_request *wsgi_req) {
7878
int i;
7979
sigset_t smask;
8080

81-
82-
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &i);
83-
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &i);
8481
pthread_setspecific(uwsgi.tur_key, (void *) wsgi_req);
8582

8683
if (core_id > 0) {

core/utils.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,12 +1034,6 @@ void uwsgi_destroy_request(struct wsgi_request *wsgi_req) {
10341034

10351035
close_and_free_request(wsgi_req);
10361036

1037-
int foo;
1038-
if (uwsgi.threads > 1) {
1039-
// now the thread can die...
1040-
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &foo);
1041-
}
1042-
10431037
// reset for avoiding following requests to fail on non-uwsgi protocols
10441038
// thanks Marko Tiikkaja for catching it
10451039
wsgi_req->uh->_pktsize = 0;
@@ -1131,11 +1125,6 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
11311125
func(wsgi_req);
11321126
}
11331127

1134-
if (uwsgi.threads > 1) {
1135-
// now the thread can die...
1136-
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &tmp_id);
1137-
}
1138-
11391128
// leave harakiri mode
11401129
if (uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].harakiri > 0) {
11411130
set_harakiri(wsgi_req, 0);
@@ -1583,18 +1572,12 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) {
15831572
}
15841573
}
15851574

1586-
// kill the thread after the request completion
1587-
if (uwsgi.threads > 1)
1588-
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ret);
1589-
15901575
if (uwsgi.signal_socket > -1 && (interesting_fd == uwsgi.signal_socket || interesting_fd == uwsgi.my_signal_socket)) {
15911576

15921577
thunder_unlock;
15931578

15941579
uwsgi_receive_signal(wsgi_req, interesting_fd, "worker", uwsgi.mywid);
15951580

1596-
if (uwsgi.threads > 1)
1597-
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ret);
15981581
return -1;
15991582
}
16001583

@@ -1605,8 +1588,6 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) {
16051588
wsgi_req->fd = wsgi_req->socket->proto_accept(wsgi_req, interesting_fd);
16061589
thunder_unlock;
16071590
if (wsgi_req->fd < 0) {
1608-
if (uwsgi.threads > 1)
1609-
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ret);
16101591
return -1;
16111592
}
16121593

@@ -1621,8 +1602,6 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) {
16211602
}
16221603

16231604
thunder_unlock;
1624-
if (uwsgi.threads > 1)
1625-
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ret);
16261605
return -1;
16271606
}
16281607

core/uwsgi.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,53 +1230,21 @@ void warn_pipe() {
12301230
void wait_for_threads() {
12311231
int i, ret;
12321232

1233-
// on some platform thread cancellation is REALLY flaky
1233+
// This option was added because we used pthread_cancel().
1234+
// thread cancellation is REALLY flaky
12341235
if (uwsgi.no_threads_wait) return;
12351236

1236-
int sudden_death = 0;
1237-
12381237
pthread_mutex_lock(&uwsgi.six_feet_under_lock);
1239-
for (i = 1; i < uwsgi.threads; i++) {
1240-
if (!pthread_equal(uwsgi.workers[uwsgi.mywid].cores[i].thread_id, pthread_self())) {
1241-
if (pthread_cancel(uwsgi.workers[uwsgi.mywid].cores[i].thread_id)) {
1242-
uwsgi_error("pthread_cancel()\n");
1243-
sudden_death = 1;
1244-
}
1245-
}
1246-
}
1247-
1248-
if (sudden_death)
1249-
goto end;
12501238

12511239
// wait for thread termination
1252-
for (i = 1; i < uwsgi.threads; i++) {
1240+
for (i = 0; i < uwsgi.threads; i++) {
12531241
if (!pthread_equal(uwsgi.workers[uwsgi.mywid].cores[i].thread_id, pthread_self())) {
12541242
ret = pthread_join(uwsgi.workers[uwsgi.mywid].cores[i].thread_id, NULL);
12551243
if (ret) {
12561244
uwsgi_log("pthread_join() = %d\n", ret);
12571245
}
12581246
}
12591247
}
1260-
1261-
// cancel initial thread last since after pthread_cancel() and
1262-
// pthread_join() is called on it, the whole process will appear to be
1263-
// a zombie. although it won't eliminate process zombie time, but it
1264-
// should minimize it.
1265-
if (!pthread_equal(uwsgi.workers[uwsgi.mywid].cores[0].thread_id, pthread_self())) {
1266-
if (pthread_cancel(uwsgi.workers[uwsgi.mywid].cores[0].thread_id)) {
1267-
uwsgi_error("pthread_cancel() on initial thread\n");
1268-
goto end;
1269-
}
1270-
1271-
ret = pthread_join(uwsgi.workers[uwsgi.mywid].cores[0].thread_id, NULL);
1272-
if (ret) {
1273-
uwsgi_log("pthread_join() = %d on initial thread\n", ret);
1274-
}
1275-
}
1276-
1277-
end:
1278-
1279-
pthread_mutex_unlock(&uwsgi.six_feet_under_lock);
12801248
}
12811249

12821250

0 commit comments

Comments
 (0)