struct timespec global_list[LISTSIZE]; int listcount = 0;
void checklist(conststruct timespec *list, int size)
{ int i, j; conststruct timespec *a, *b;
/* scan the list */ for (i = 0; i < size-1; i++) {
a = &list[i];
b = &list[i+1];
/* look for any time inconsistencies */ if ((b->tv_sec <= a->tv_sec) &&
(b->tv_nsec < a->tv_nsec)) {
/* flag other threads */
done = 1;
/*serialize printing to avoid junky output*/
pthread_mutex_lock(&print_lock);
/* dump the list */
printf("\n"); for (j = 0; j < size; j++) { if (j == i)
printf("---------------\n");
printf("%lu:%lu\n", list[j].tv_sec, list[j].tv_nsec); if (j == i+1)
printf("---------------\n");
}
printf("[FAILED]\n");
pthread_mutex_unlock(&print_lock);
}
}
}
/* The shared thread shares a global list *thateachthreadfillswhileholdingthelock. *Thisstressesclocksynchronizationacrosscpus.
*/ void *shared_thread(void *arg)
{ while (!done) { /* protect the list */
pthread_mutex_lock(&list_lock);
/* see if we're ready to check the list */ if (listcount >= LISTSIZE) {
checklist(global_list, LISTSIZE);
listcount = 0;
}
clock_gettime(CLOCK_MONOTONIC, &global_list[listcount++]);
/* Each independent thread fills in its own *list.Thisstressesclock_gettime()lockcontention.
*/ void *independent_thread(void *arg)
{ struct timespec my_list[LISTSIZE]; int count;
while (!done) { /* fill the list */ for (count = 0; count < LISTSIZE; count++)
clock_gettime(CLOCK_MONOTONIC, &my_list[count]);
checklist(my_list, LISTSIZE);
} return NULL;
}
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.