Mail Archives: cygwin/2012/05/22/09:27:02
--------------070403050802080709040303
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
>> Testcase cancel deferred:
>> Works with 1.7.9 and 20120517 snapshot, fails (hangs) with 1.7.12-1
>> and 1.7.15-1.
> If that works in the snapshot anyway, I'm not going to look into that
> one.
It worked in the reduced testcase with sem_wait(). With read() it’s
still half-broken. See below.
>> Testcase cancel asynchronous:
>> Async cancel seems to have no effect with any tested version.
> I think I found a solution for this problem. See the comment in the
> patch at
> http://sourceware.org/cgi-bin/cvsweb.cgi/src/winsup/cygwin/thread.cc.diff?cvsroot=src&r1=1.258&r2=1.259
> Please test the today's developer snapshot.
Asynchronous cancel seems to work as well as deferred cancel now. Thanks.
Both cancel types work with sem_wait() and pause() now, but for threads
blocked in read() they’re still unreliable. Only one of three blocked
threads is killed in the attached updated testcases.
>> Testcase signal/kill:
>> Signals may or may not reach the correct thread with 1.7.12-1 and newer.
> Confirmed. [...] This is cgf's domain so I leave it at that for now.
Okay, I’ll hope for him to respond then.
Otto
--------------070403050802080709040303
Content-Type: text/x-csrc;
name="testcase_cancel_asynchronous.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="testcase_cancel_asynchronous.c"
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
pthread_t tids[3];
static void cleanup_handler(void *arg) {
int *intptr = (int*)arg;
pthread_t self = pthread_self();
fprintf(stderr, "Thread %i exiting (%p)\n", *intptr, self);
}
static void* simplethread(void *arg) {
int *intptr = (int*)arg;
pthread_t self = pthread_self();
fprintf(stderr, "Thread %i starting (%p)\n", *intptr, self);
char buffer[1] __attribute((unused));
pthread_cleanup_push(&cleanup_handler, intptr);
int oldtype;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
fprintf(stderr, "Changing canceltype from %i to %i\n", oldtype, PTHREAD_CANCEL_ASYNCHRONOUS);
while (1) {
if (read(STDIN_FILENO, buffer, 1) <= 0) {
fprintf(stderr, "Thread %i encountered an error: %s (%p)\n",
*intptr, strerror(errno), self);
} else {
fprintf(stderr, "Thread %i woke up just fine\n", *intptr);
}
}
pthread_cleanup_pop(1);
return NULL;
}
int main() {
fprintf(stderr, "Testing asynchronous pthread_cancel()\n\n");
int i;
int result;
for (i=0; i<3; i++) {
int *intptr = (int*)malloc(sizeof(int));
*intptr = i;
result = pthread_create(tids+i, NULL, &simplethread, intptr);
if (result != 0) {
fprintf(stderr, "Can't create thread: %s\n", strerror(result));
return 1;
}
}
sleep(1);
fprintf(stderr, "\n");
int mainint = 42;
pthread_cleanup_push(&cleanup_handler, &mainint);
for (i=2; i>=0; i--) {
fprintf(stderr, "Cancelling thread %i (%p)\n", i, tids[i]);
result = pthread_cancel(tids[i]);
if (result != 0) {
fprintf(stderr, "Error during pthread_cancel: %s\n", strerror(result));
}
sleep(1);
}
fprintf(stderr, "\n");
for (i=0; i<3; i++) {
result = pthread_kill(tids[i], 0);
if (result == 0) {
fprintf(stderr, "Thread %i is still there (%p)\n", i, tids[i]);
} else {
fprintf(stderr, "Thread %i is gone (%p)\n", i, tids[i]);
}
}
pthread_cleanup_pop(0);
return 0;
}
--------------070403050802080709040303
Content-Type: text/x-csrc;
name="testcase_cancel_deferred.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="testcase_cancel_deferred.c"
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
pthread_t tids[3];
static void cleanup_handler(void *arg) {
int *intptr = (int*)arg;
pthread_t self = pthread_self();
fprintf(stderr, "Thread %i exiting (%p)\n", *intptr, self);
}
static void* simplethread(void *arg) {
int *intptr = (int*)arg;
pthread_t self = pthread_self();
fprintf(stderr, "Thread %i starting (%p)\n", *intptr, self);
char buffer[1] __attribute((unused));
pthread_cleanup_push(&cleanup_handler, intptr);
while (1) {
if (read(STDIN_FILENO, buffer, 1) <= 0) {
fprintf(stderr, "Thread %i encountered an error: %s (%p)\n",
*intptr, strerror(errno), self);
} else {
fprintf(stderr, "Thread %i woke up just fine\n", *intptr);
}
}
pthread_cleanup_pop(1);
return NULL;
}
int main() {
fprintf(stderr, "Testing deferred pthread_cancel()\n\n");
int i;
int result;
for (i=0; i<3; i++) {
int *intptr = (int*)malloc(sizeof(int));
*intptr = i;
result = pthread_create(tids+i, NULL, &simplethread, intptr);
if (result != 0) {
fprintf(stderr, "Can't create thread: %s\n", strerror(result));
return 1;
}
}
sleep(1);
fprintf(stderr, "\n");
int mainint = 42;
pthread_cleanup_push(&cleanup_handler, &mainint);
for (i=2; i>=0; i--) {
fprintf(stderr, "Cancelling thread %i (%p)\n", i, tids[i]);
result = pthread_cancel(tids[i]);
if (result != 0) {
fprintf(stderr, "Error during pthread_cancel: %s\n", strerror(result));
}
sleep(1);
}
fprintf(stderr, "\n");
for (i=0; i<3; i++) {
result = pthread_kill(tids[i], 0);
if (result == 0) {
fprintf(stderr, "Thread %i is still there (%p)\n", i, tids[i]);
} else {
fprintf(stderr, "Thread %i is gone (%p)\n", i, tids[i]);
}
}
pthread_cleanup_pop(0);
return 0;
}
--------------070403050802080709040303
Content-Type: text/plain; charset=us-ascii
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
--------------070403050802080709040303--
- Raw text -