/* Licensed to the Apache Software Foundation (ASF) under one or more *contributorlicenseagreements.SeetheNOTICEfiledistributedwith *thisworkforadditionalinformationregardingcopyrightownership. *TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0 *(the"License");youmaynotusethisfileexceptincompliancewith *theLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
lock_it.l_whence = SEEK_SET; /* from current point */
lock_it.l_start = 0; /* -"- */
lock_it.l_len = 0; /* until end of file */
lock_it.l_type = F_WRLCK; /* set exclusive/write lock */
lock_it.l_pid = 0; /* pid not actually interesting */
unlock_it.l_whence = SEEK_SET; /* from current point */
unlock_it.l_start = 0; /* -"- */
unlock_it.l_len = 0; /* until end of file */
unlock_it.l_type = F_UNLCK; /* set exclusive/write lock */
unlock_it.l_pid = 0; /* pid not actually interesting */
printf("opening test-lock-thing in current directory\n");
fcntl_fd = open("test-lock-thing", O_CREAT | O_WRONLY | O_EXCL, 0644); if (fcntl_fd == -1)
{
perror ("open");
fprintf (stderr, "Cannot open lock file: %s\n", "test-lock-thing"); exit (1);
}
unlink("test-lock-thing");
}
void accept_mutex_init(void)
{ #ifdef NEED_UNION_SEMUN /* believe it or not, you need to define this under solaris */ union semun { int val; struct semid_ds *buf;
ushort *array;
}; #endif
void main (int argc, char **argv)
{ int num_iter; int num_child; int i; struct timeval first; struct timeval last; long ms; int pid; unsignedlong *shared_counter;
if (argc != 3) {
fprintf (stderr, "Usage: time-sem num-child num iter\n"); exit (1);
}
/* allocate shared memory for the shared_counter */
shared_counter = get_shared_mem(sizeof(*shared_counter));
/* initialize counter to 0 */
*shared_counter = 0;
accept_mutex_init ();
/* parent grabs mutex until done spawning children */
accept_mutex_on ();
for (i = 0; i < num_child; ++i) {
pid = fork(); if (pid == 0) { /* child, do our thing */
accept_mutex_child_init(); for (i = 0; i < num_iter; ++i) { unsignedlong tmp;
/* a quick test to see that nothing is screwed up */ if (*shared_counter != 0) {
puts ("WTF! shared_counter != 0 before the children have been started!");
accept_mutex_off (); exit (1);
}
gettimeofday (&first, NULL); /* launch children into action */
accept_mutex_off (); for (i = 0; i < num_child; ++i) { if (wait(NULL) == -1) {
perror ("wait");
}
}
gettimeofday (&last, NULL);
last.tv_sec -= first.tv_sec;
ms = last.tv_usec - first.tv_usec; if (ms < 0) {
--last.tv_sec;
ms += 1000000;
}
last.tv_usec = ms;
printf ("%8lu.%06lu\n", last.tv_sec, last.tv_usec);
accept_mutex_cleanup();
exit(0);
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.3Bemerkung:
(vorverarbeitet am 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.