| 452 | BENCHMARK(BM_SendRecv); |
| 453 | |
| 454 | void BM_PingPong(int iters) { |
| 455 | CHECK_GT(iters, 0); |
| 456 | auto* cm = new CancellationManager(); |
| 457 | thread::ThreadPool* pool = new thread::ThreadPool(Env::Default(), "test", 1); |
| 458 | |
| 459 | // The main thread sends "foo" for iters times and receives "bar" |
| 460 | // for iters times. The other thread sends "bar" for iters times |
| 461 | // and receives "foo" for iters times. |
| 462 | Rendezvous* rendez = NewLocalRendezvous(); |
| 463 | pool->Schedule([rendez, iters]() { |
| 464 | Tensor bar = V("bar"); |
| 465 | Tensor foo(DT_STRING, TensorShape({})); |
| 466 | bool is_dead = false; |
| 467 | Rendezvous::Args args; |
| 468 | for (int i = 0; i < iters; ++i) { |
| 469 | TF_CHECK_OK(rendez->Recv(KeyFoo(), args, &foo, &is_dead)); |
| 470 | TF_CHECK_OK(rendez->Send(KeyBar(), args, bar, is_dead)); |
| 471 | } |
| 472 | CHECK_EQ("foo", V(foo)); |
| 473 | }); |
| 474 | Tensor foo = V("foo"); |
| 475 | Tensor bar(DT_STRING, TensorShape({})); |
| 476 | bool is_dead = false; |
| 477 | Rendezvous::Args args; |
| 478 | args.cancellation_manager = cm; |
| 479 | for (int i = 0; i < iters; ++i) { |
| 480 | TF_CHECK_OK(rendez->Send(KeyFoo(), args, foo, is_dead)); |
| 481 | TF_CHECK_OK(rendez->Recv(KeyBar(), args, &bar, &is_dead)); |
| 482 | } |
| 483 | CHECK_EQ("bar", V(bar)); |
| 484 | delete pool; |
| 485 | delete cm; |
| 486 | } |
| 487 | BENCHMARK(BM_PingPong); |
| 488 | |
| 489 | } // namespace |
nothing calls this directly
no test coverage detected