apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dror Shilo" <Dror.Sh...@ericom.com>
Subject problem with apr_proc_mutex_create
Date Thu, 08 Dec 2005 13:29:02 GMT
hello
I try to use apr_proc_mutex_create with APR_LOCK_FLOCK
The second process is not the chilled of the fist one:
and it give error 17

this is my program:
// globallock.c
//

#include <stdio.h>
#include <stdlib.h> 
#include "apr.h"
#include "apr_proc_mutex.h"
#include "apr_time.h"
int main()
{
	apr_pool_t* context = 0;
	apr_initialize();
	atexit(apr_terminate);                                            \
	apr_pool_create(&context, 0);
	apr_proc_mutex_t *mutex = 0;
	int ret = apr_proc_mutex_create(&mutex,"trylock", APR_LOCK_FLOCK,context);
	if(ret)
	{
		printf("error %d\n",ret);
		return 1;
	}
	printf("Press <RETURN> to try to get lock: ");
	getchar();
	printf("Trying to get lock...");
	apr_proc_mutex_lock(mutex);
	printf("got lock\n");
	printf("Press <RETURN> to release lock: ");
	getchar();	
	apr_proc_mutex_unlock(mutex);
	printf("Unlocked.\n");
	apr_proc_mutex_destroy(mutex);
	return 0;
}

I have a program that work good but not using apr:

/*
** lockdemo.c -- shows off your system's file locking.  Rated R.
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
                     /* l_type   l_whence  l_start  l_len  l_pid   */
    struct flock fl = { F_WRLCK, SEEK_SET, 0,       0,     0 };
    int fd;

    fl.l_pid = getpid();

    if (argc > 1) 
        fl.l_type = F_RDLCK;

    if ((fd = open("lockdemo.c", O_RDWR)) == -1) {
        perror("open");
        exit(1);
    }

    printf("Press <RETURN> to try to get lock: ");
    getchar();
    printf("Trying to get lock...");

    if (fcntl(fd, F_SETLKW, &fl) == -1) {
        perror("fcntl");
        exit(1);
    }

    printf("got lock\n");
    printf("Press <RETURN> to release lock: ");
    getchar();

    fl.l_type = F_UNLCK;  /* set to unlock same region */

    if (fcntl(fd, F_SETLK, &fl) == -1) {
        perror("fcntl");
        exit(1);
    }

    printf("Unlocked.\n");

    close(fd);
}

can any one help me to work it with apr
Dror Shilo
Ericom software

 <<globallock.c>>  <<lockdemo.c>> 


Mime
View raw message