Commit 9fcecfe1 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

test: Make testee-threads to create thread inside thread

And open a file as well
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 611debc3
......@@ -18,11 +18,40 @@
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
static int counter;
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment