test: Make testee-threads to create thread inside thread

And open a file as well

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2011-10-20 13:46:13 +04:00
parent 611debc312
commit 9fcecfe1a2

View file

@ -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);