Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 302F0179FF for ; Tue, 30 Sep 2014 15:31:12 +0000 (UTC) Received: (qmail 39418 invoked by uid 500); 30 Sep 2014 15:31:11 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 39374 invoked by uid 500); 30 Sep 2014 15:31:11 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 39362 invoked by uid 99); 30 Sep 2014 15:31:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Sep 2014 15:31:11 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ylavic.dev@gmail.com designates 209.85.212.179 as permitted sender) Received: from [209.85.212.179] (HELO mail-wi0-f179.google.com) (209.85.212.179) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Sep 2014 15:30:46 +0000 Received: by mail-wi0-f179.google.com with SMTP id d1so3797779wiv.12 for ; Tue, 30 Sep 2014 08:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=6CG3bXQqbWX70IkU/CD6wcE4uYtp+AsJX5zOxlkDYkw=; b=DWQqwnBoh+u8NWyObK4JWzRliZ2K7BcahdxfU2GH+LAS/kMamT+vrE/JPBLj8vdKPD S89OqDpAqsibJNAO5mtuehd9pg3dMEkA8D8ooN2iIFNBNTTmjognG7h/nCpOfw0EBrpn Z9j1ysqibb0VoRlBpwYe47nYfrq/YNVxJrnry1aAxZ5w0OpiloQF2YKn1Lxa7uOngXdF liKaoleFrVYy8r/5ihNjQkBz/rvn/HseBGgeHTQ77G6Hmj/1oqUoiNrfzg4qm2QTIaO7 mp4oBiFfpxgtxl9MnhvoIZzxiFqUb1RNy3FhsyKXRTHpeiMzcGd/U1xIGaCJhtOdsbrW hkRw== MIME-Version: 1.0 X-Received: by 10.194.11.10 with SMTP id m10mr52094816wjb.77.1412091045431; Tue, 30 Sep 2014 08:30:45 -0700 (PDT) Received: by 10.216.13.66 with HTTP; Tue, 30 Sep 2014 08:30:45 -0700 (PDT) In-Reply-To: <54295C2F.80307@lenk.info> References: <54295C2F.80307@lenk.info> Date: Tue, 30 Sep 2014 17:30:45 +0200 Message-ID: Subject: Re: How to wait on a global lock with timeout From: Yann Ylavic To: modules-dev@httpd.apache.org Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org Hi Micha, On Mon, Sep 29, 2014 at 3:18 PM, Micha Lenk wrote: > in an Apache module I am in the need to wait for a global lock (e.g. an > apr_global_mutex_t), but in theory the lock might not get released by the > other process in a timely manner, so I would like to limit the time to wait > for the lock. What do you suggest me to do? I have been working on a patch to provide apr_[thread/proc]_mutex_timedlock() in APR, but did not finish the work mostly because of APR_ENOTIMPL on some mutex mechanisms (mainly Windows CRITICAL_SECTIONs which lack the functionality, making the APR abstraction quite useless IMO, or at least unix specific). Maybe I'll have a new look at it these days if I have the time to. For now you may have the possibility to use native mutex functions (eg. pthread_mutex_timedlock or WaitForSingleObject) with the native object retrieved by ap_os_[thread/proc]_mutex_get(), but this requires either to create the mutex with a mechanism supporting the timeout, or the existing mutex to have such a mechanism. Hence this may be non-portable code, or with many APR_HAS_*_SERIALIZE, and still the problem with platforms that don't support it... Regards, Yann.