From 9fcecfe1a2c9ced2ec428920c2fc4bb7df447477 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Thu, 20 Oct 2011 13:46:13 +0400 Subject: [PATCH] test: Make testee-threads to create thread inside thread And open a file as well Signed-off-by: Cyrill Gorcunov --- test/testee-threads.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/test/testee-threads.c b/test/testee-threads.c index fa201eb96..689fa9ad1 100644 --- a/test/testee-threads.c +++ b/test/testee-threads.c @@ -18,11 +18,40 @@ static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; static int counter; -static void *f1(void *arg) +static void *ff1(void *arg) { void *map_unreadable = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); (void)map_unreadable; + while (1) { + pthread_mutex_lock(&mtx); + + counter++; + printf("%d: Counter value: %d\n", getpid(), counter); + + pthread_mutex_unlock(&mtx); + sleep(5); + } + + return NULL; +} + +static void *f1(void *arg) +{ + const char name[] = "f1-file"; + pthread_t th; + int fd; + void *map_unreadable = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + (void)map_unreadable; + + unlink(name); + fd = open(name, O_CREAT, 0644); + if (fd >= 0) + write(fd, name, sizeof(name)); + + if (pthread_create(&th, NULL, &ff1, NULL)) + perror("Cant create thread"); + while (1) { pthread_mutex_lock(&mtx);