ASF Bugzilla – Attachment 17771 Details for
Bug 38758
process mutex trylock functions for unix
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
test program for trylock functions
test_try.c (text/x-csrc), 2.62 KB, created by
Chris Darroch
on 2006-02-22 22:39:09 UTC
(
hide
)
Description:
test program for trylock functions
Filename:
MIME Type:
Creator:
Chris Darroch
Created:
2006-02-22 22:39:09 UTC
Size:
2.62 KB
patch
obsolete
>#include <stdio.h> >#include <strings.h> >#include <apr.h> >#include <apr_pools.h> >#include <apr_proc_mutex.h> > >int main(int argc, const char * const *argv) >{ > apr_status_t s; > apr_pool_t *p; > apr_proc_mutex_t *l; > apr_lockmech_e mech = APR_LOCK_DEFAULT; > char buf[100]; > int pid; > int i; > > apr_app_initialize(&argc, &argv, NULL); > atexit(apr_terminate); > > apr_pool_create(&p, NULL); > > if(argc == 2) > { > if(strcmp("flock", argv[1]) == 0) > mech = APR_LOCK_FLOCK; > else if(strcmp("fcntl", argv[1]) == 0) > mech = APR_LOCK_FCNTL; > else if(strcmp("posix", argv[1]) == 0) > mech = APR_LOCK_POSIXSEM; > else if(strcmp("sysv", argv[1]) == 0) > mech = APR_LOCK_SYSVSEM; > else if(strcmp("pthread", argv[1]) == 0) > mech = APR_LOCK_PROC_PTHREAD; > } > > s = apr_proc_mutex_create(&l, "/tmp/test_hang", mech, p); > if(s) > { > fprintf(stderr, "unable to create lock: %d, %s\n", > s, apr_strerror(s, buf, 100)); > } > > printf("lock name: %s\n", apr_proc_mutex_name(l)); > > if((pid = fork()) == -1) > { > fprintf(stderr, "unable to fork\n"); > exit(1); > } > > if(pid) > { > i = 0; > s = APR_EBUSY; > while(s == APR_EBUSY) > { > if(++i == 2) > printf("parent still waiting\n"); > sleep(1); > s = apr_proc_mutex_trylock(l); > } > } > else > { > apr_initialize(); > > s = apr_proc_mutex_child_init(&l, "/tmp/test_hang", p); > if(s) > { > fprintf(stderr, "unable to init lock in child: %d, %s\n", > s, apr_strerror(s, buf, 100)); > } > > s = apr_proc_mutex_trylock(l); > } > > if(s) > { > fprintf(stderr, "unable to acquire lock (%s): %d, %s\n", > (pid ? "parent" : "child"), s, apr_strerror(s, buf, 100)); > goto do_exit; > } > > if(pid) > printf("parent acquired lock\n"); > else > { > printf("child %d acquired lock ... now kill me!\n", getpid()); > > for(i = 0; i < 10; ++i) > { > printf("%d\n", i); > sleep(1); > } > } > > s = apr_proc_mutex_unlock(l); > if(s) > { > fprintf(stderr, "unable to release lock (%s): %d, %s\n", > (pid ? "parent" : "child"), s, apr_strerror(s, buf, 100)); > } > >do_exit: > if(!pid) > { > printf("child exiting\n"); > exit(0); > } > > s = apr_proc_mutex_destroy(l); > if(s) > { > fprintf(stderr, "unable to destroy lock: %d, %s\n", > s, apr_strerror(s, buf, 100)); > } > > printf("parent exiting\n"); > exit(0); >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 38758
:
17769
|
17770
| 17771 |
17772
|
17878