Last active
February 18, 2016 16:49
-
-
Save mitchhentges/db270f2749d4bbc7aeca to your computer and use it in GitHub Desktop.
Calculating timings for a sequential-lock-by-lock algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int compute(int, int); | |
int main(int argc, char* argv[]) | |
{ | |
printf("\t distributed-lock-timings\n"); | |
printf("Will calculate total time (in units of '1' per 'operation', where 'operation' is requesting a lock, performing transaction, or removing a lock)\n"); | |
printf("These timings are based on two concurrent requests: one trying to change three resources, the other trying to change just one\n"); | |
printf("It is assume that each lock is being acquired sequentially, per request\n"); | |
printf("The requests are running in parallel (other than when blocked by resource contention, of course\n"); | |
printf("\n"); | |
printf("The resources are A, B, and C. The \"big\" request will lock in the following order: [A, B, C]\n"); | |
printf("c: The average time it takes to complete the two requests\n"); | |
printf("w: The total time that one of the requests was suspended (due to resource contention)\n"); | |
printf("n: Which resource that the small request going to affect, numbered in the order that it is locked by the big request: A=0, B=1, C=2 (A is locked first, so is 0)\n"); | |
printf("t: offset between small request starting and big request starting\n"); | |
printf("\n\n"); | |
printf("*--*--*-------*-------*\n"); | |
printf("| n| t| c| w|\n"); | |
for (int i = 0; i < 3; i++) | |
{ | |
printf("*--*--*-------*-------*\n"); | |
printf("|%2d| | | |\n", i); | |
printf("*--*--*-------*-------*\n"); | |
for (int j = -4; j < 8; j++) | |
{ | |
printf("|%2d|%2d|%7.2f|%7.2f|\n", i, j, (7 + 3 + compute(i, j)) / 2.0f, compute(i, j) / 2.0f); | |
} | |
} | |
printf("*--*--*-------*-------*\n"); | |
} | |
int compute(int n, int t) | |
{ | |
int toReturn = (t > n) | |
? 7 - t - n | |
: 3 + t - n; | |
return (toReturn < 0) ? 0 : toReturn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current output: