ywkaras commented on code in PR #9394:
URL: https://github.com/apache/trafficserver/pull/9394#discussion_r1111109669


##########
src/tscpp/util/unit_tests/benchmark_shared_mutex.cc:
##########
@@ -0,0 +1,130 @@
+/** @file
+
+  Micro Benchmark tool for shared_mutex - requires Catch2 v2.9.0+
+
+  - e.g. example of running 64 threads with read/write rate is 100:1
+  ```
+  $ taskset -c 0-63 ./benchmark_shared_mutex --ts-nthreads 64 --ts-nloop 1000 
--ts-nread 100 --ts-nwrite 1
+  ```
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+      http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#define CATCH_CONFIG_ENABLE_BENCHMARKING
+#define CATCH_CONFIG_RUNNER
+
+#include "catch.hpp"
+
+#include "tscpp/util/Bravo.h"
+
+#include <mutex>
+#include <shared_mutex>
+#include <thread>
+
+namespace
+{
+// Args
+struct Conf {
+  int nloop    = 1;
+  int nthreads = 1;
+  int nread    = 1;
+  int nwrite   = 1;
+};
+
+Conf conf;
+thread_local int counter = 0;
+
+template <typename T, typename S>
+void
+run(T &mutex)
+{
+  std::thread list[conf.nthreads];
+
+  for (int i = 0; i < conf.nthreads; i++) {
+    new (&list[i]) std::thread{[](T &mutex) {

Review Comment:
   Why not just:
   ```
   list[i] = std::thread{...
   ```
   ?  std::thread isn't copyable, but it's moveable.  What your doing assumes 
that ~std::thread() is vacuous when the thread is constructed with the default 
constructor.  That's probably true in this case, but it's better practice to 
not make such assumptions unless it's really necessary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to