ReentrantLock – should we check who holds the lock while unlocking in finally block?

A simple snippet get stuck often when delay is slightly high: public String getToken(String userId, ReentrantLock lock) throws InterruptedException { try { // lock is in a cache of ConcurrentHashMap with key of userId if (!lock.tryLock(LOCK_TIMEOUT_SEC, TimeUnit.SECONDS)) { throw new AppException("Could not get lock in " + LOCK_TIMEOUT_SEC + "s"); // 10 sec } String… Read More ReentrantLock – should we check who holds the lock while unlocking in finally block?

why do we need a reference count in this Reentrant lock example?

Why do we need m_refCount in the example below? What would happen if we leaved it out and also removed the if statement and just left its body there ? class ReentrantLock32 { std::atomic<std::size_t> m_atomic; std::int32_t m_refCount; public: ReentrantLock32() : m_atomic(0), m_refCount(0) {} void Acquire() { std::hash<std::thread::id> hasher; std::size_t tid = hasher(std::this_thread::get_id()); // if this… Read More why do we need a reference count in this Reentrant lock example?

Can std::future cause coredump without get or wait

void func() { std::future<int> fut = std::async(std::launch::async, []{ std::this_thread::sleep_for(std::chrono::seconds(10)); return 8; }); return; } Let’s say that I have such a function. An object fut of std::future<int> is initialized with a std::async job, which will return an integer in the future. But the fut will be immediately released after the function func returns. Is there… Read More Can std::future cause coredump without get or wait

Unable to read/write to file from Lua script running from HAPRoxy

I was using Lua with HAProxy to write logs into custom log file. Although my script is running totally fine. But I don’t see anything written in my text file. Here is my lua script which I am loading from HAProxy.cfg. local function foo(value) — MY CODE — file = io.open("test.lua", "a") io.output(file) io.write("The value… Read More Unable to read/write to file from Lua script running from HAPRoxy

How to remove Sonar issue on Java stream "Refactor the code so this stream pipeline is used"

I’m working on a project (Java 17) where I have a list of object with two properties, actionId (String) and right (boolean). I’m trying to get the actionId for object with right = true and store the result as List of String. This is my code: List<String> usserValidActionsArray = userActionGatewayDTO.stream().filter(UserActionGatewayDTO::getRight) .map(UserActionGatewayDTO::getActionId).toList(); My code works fine,… Read More How to remove Sonar issue on Java stream "Refactor the code so this stream pipeline is used"