}
void *
-test2(void *x)
+test2(int i)
{
- int i = * (int *) x;
-
tprintf ("test2: client %d acquire a release a\n", i);
lc[i]->acquire(a);
tprintf ("test2: client %d acquire done\n", i);
}
void *
-test3(void *x)
+test3(int i)
{
- int i = * (int *) x;
-
tprintf ("test3: client %d acquire a release a concurrent\n", i);
for (int j = 0; j < 10; j++) {
lc[i]->acquire(a);
}
void *
-test4(void *x)
+test4(int i)
{
- int i = * (int *) x;
-
tprintf ("test4: thread %d acquire a release a concurrent; same clnt\n", i);
for (int j = 0; j < 10; j++) {
lc[0]->acquire(a);
}
void *
-test5(void *x)
+test5(int i)
{
- int i = * (int *) x;
-
tprintf ("test5: client %d acquire a release a concurrent; same and diff clnt\n", i);
for (int j = 0; j < 10; j++) {
if (i < 5) lc[0]->acquire(a);
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
- srandom(getpid());
+ srandom((uint32_t)getpid());
if(argc < 2) {
fprintf(stderr, "Usage: %s [host:]port [test]\n", argv[0]);
if(!test || test == 2){
// test2
- for (int i = 0; i < nt; i++) {
- int *a = new int (i);
- th[i] = std::thread(test2, a);
- }
- for (int i = 0; i < nt; i++) {
+ for (int i = 0; i < nt; i++)
+ th[i] = std::thread(test2, i);
+ for (int i = 0; i < nt; i++)
th[i].join();
- }
}
if(!test || test == 3){
tprintf("test 3\n");
// test3
- for (int i = 0; i < nt; i++) {
- int *a = new int (i);
- th[i] = std::thread(test3, a);
- }
- for (int i = 0; i < nt; i++) {
+ for (int i = 0; i < nt; i++)
+ th[i] = std::thread(test3, i);
+ for (int i = 0; i < nt; i++)
th[i].join();
- }
}
if(!test || test == 4){
tprintf("test 4\n");
// test 4
- for (int i = 0; i < 2; i++) {
- int *a = new int (i);
- th[i] = std::thread(test4, a);
- }
- for (int i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; i++)
+ th[i] = std::thread(test4, i);
+ for (int i = 0; i < 2; i++)
th[i].join();
- }
}
if(!test || test == 5){
tprintf("test 5\n");
// test 5
-
- for (int i = 0; i < nt; i++) {
- int *a = new int (i);
- th[i] = std::thread(test5, a);
- }
- for (int i = 0; i < nt; i++) {
+ for (int i = 0; i < nt; i++)
+ th[i] = std::thread(test5, i);
+ for (int i = 0; i < nt; i++)
th[i].join();
- }
}
tprintf ("%s: passed all tests successfully\n", argv[0]);