From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D4E1F46970E for ; Tue, 24 Dec 2019 18:27:37 +0300 (MSK) References: <73ebdf94c8f03fca216de9141c6541870b1ed938.1575390549.git.lvasiliev@tarantool.org> <20191203180257.GA4364@atlas> <65b9d108-fe36-1c9b-82c0-60e98efce658@tarantool.org> <20191205072706.GA16690@atlas> <442799bc-16a2-d5db-dc8c-d4663adfbe81@tarantool.org> <20191223125519.GA25824@atlas> From: Leonid Vasiliev Message-ID: <7b4e53cf-f2a8-1dca-4eb1-0c315f0b8932@tarantool.org> Date: Tue, 24 Dec 2019 18:27:36 +0300 MIME-Version: 1.0 In-Reply-To: <20191223125519.GA25824@atlas> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH] Add a cancellation guard to cpipe flush callback List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Konstantin Osipov , alexander.turenko@tarantool.org, tarantool-patches@dev.tarantool.org On 12/23/19 3:55 PM, Konstantin Osipov wrote: > * Leonid Vasiliev [19/12/23 15:48]: >> + while(hang_endpoint.mutex.__data.__lock < 2) { >> + usleep(100); >> + } > > How does this work? Is there a way to not look inside mutex? > Other alternatives (which I can come up with) add possible races or cancellation points. We must cancel the thread before cancellation point in ev_async_send (ev_async_send(endpoint->consumer, &endpoint->async);) and as close as possible to it for to reproduce a behavior from https://github.com/tarantool/tarantool/issues/4127 . How it's work (it's hack): mutex.__data.__lock == 0 - mutex unlocked mutex.__data.__lock == 1 - mutex locked mutex.__data.__lock == 2 - waiters are exists We just wait while the canceled worker try to lock the endpoint mutex and cancelate thread at the moment. if you have any ideas how this can be done better and without possible races, tell me. And yes, I must to disable this dirty test for OSes other than Linux. --- diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 339521489..fb8f74be0 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -98,8 +98,10 @@ target_link_libraries(cbus_stress.test core stat) add_executable(cbus.test cbus.c) target_link_libraries(cbus.test core unit stat) -add_executable(cbus_hang.test cbus_hang.c) -target_link_libraries(cbus_hang.test core unit stat) +if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux") + add_executable(cbus_hang.test cbus_hang.c) + target_link_libraries(cbus_hang.test core unit stat) +endif ()