diff options
author | LAN-TW <lantw44@gmail.com> | 2012-11-14 09:44:26 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2012-11-14 09:50:06 +0800 |
commit | a0a8496f1e04dc964e29cc4661193e92662eaffd (patch) | |
tree | 658e3c09a6d4ba9f3677e2a3e692ac3a4103ed72 /src/mkchild.c | |
parent | a7aee0e7423dfe23bd562f1f0f0a981bfbb2ff17 (diff) | |
download | sctjudge-a0a8496f1e04dc964e29cc4661193e92662eaffd.tar.gz sctjudge-a0a8496f1e04dc964e29cc4661193e92662eaffd.tar.zst sctjudge-a0a8496f1e04dc964e29cc4661193e92662eaffd.zip |
去除所有 PTHREAD_CANCEL_ASYNCHRONOUS 以避免中斷位置不正確造成問題
解決此已知問題:在 FreeBSD 上如果受測程式太快結束,有機會導致本程式無法結束。
目前的做法事都先改成 PTHREAD_CANCEL_DEFERRED 並加入 cancel point,但我在想之
後應該要想辦法把所有 pthread_cancel() 都去掉。
Diffstat (limited to 'src/mkchild.c')
-rw-r--r-- | src/mkchild.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/mkchild.c b/src/mkchild.c index 3325632..ee370f5 100644 --- a/src/mkchild.c +++ b/src/mkchild.c @@ -95,6 +95,10 @@ static const char* childmsg_text[SCTCHILD_MSGMAX] = { }; static void sctjudge_makechild_cleanup_p1(void){ + /* 避免有 thread 卡在 sem 上砍不掉 */ + sem_post(&addthr); + sem_post(&addthr); + pthread_mutex_lock(&tkill_mx); if(tkill_yes){ tkill_yes = 0; @@ -273,7 +277,6 @@ static int read_size(int fd, void* buf, size_t count){ void* sctjudge_makechild(void* arg){ /* 首先等所有 thread 都啟動完成再開始動作 */ sem_wait(&mcthr); - sem_destroy(&mcthr); /* 宣告變數囉! */ int i; @@ -425,10 +428,9 @@ void* sctjudge_makechild(void* arg){ close(childpipe[0]); /* 現在我們確定受測程式已經在執行了,所以需要記錄一下時間 - * 通知其他 thread,然後就可以把 semaphore 丟掉了 */ + * 通知其他 thread */ sem_post(&addthr); sem_post(&addthr); - sem_destroy(&addthr); /* 開始要 wait 了,莫名其妙 stop 的程式我最多只會送 * 5 次 SIGCONT 給你(避免進入無限迴圈) |