Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E40E7200C3E for ; Tue, 21 Mar 2017 17:22:50 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E28DA160B68; Tue, 21 Mar 2017 16:22:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 383F2160B74 for ; Tue, 21 Mar 2017 17:22:50 +0100 (CET) Received: (qmail 65682 invoked by uid 500); 21 Mar 2017 16:22:49 -0000 Mailing-List: contact hdfs-dev-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list hdfs-dev@hadoop.apache.org Received: (qmail 65671 invoked by uid 99); 21 Mar 2017 16:22:49 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Mar 2017 16:22:49 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 9B5161A7BAE for ; Tue, 21 Mar 2017 16:22:48 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.349 X-Spam-Level: X-Spam-Status: No, score=-99.349 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_NEUTRAL=0.652, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id kf7LH02jG3AB for ; Tue, 21 Mar 2017 16:22:47 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 2D99660CE9 for ; Tue, 21 Mar 2017 16:22:47 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 3E8F6E0059 for ; Tue, 21 Mar 2017 16:22:43 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 0A640254D7 for ; Tue, 21 Mar 2017 16:22:42 +0000 (UTC) Date: Tue, 21 Mar 2017 16:22:42 +0000 (UTC) From: "James Clampffer (JIRA)" To: hdfs-dev@hadoop.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (HDFS-11556) libhdfs++: Improve the usage of std::promise and std::future for sync shims MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 21 Mar 2017 16:22:51 -0000 James Clampffer created HDFS-11556: -------------------------------------- Summary: libhdfs++: Improve the usage of std::promise and std::future for sync shims Key: HDFS-11556 URL: https://issues.apache.org/jira/browse/HDFS-11556 Project: Hadoop HDFS Issue Type: Sub-task Reporter: James Clampffer Assignee: James Clampffer There's two issues with the current promise/future situation being used in the synchronous shims. 1) C++ std::promise and std::futures aren't particularly intuitive (at least for me). Logically it makes sense to think of the promise and future objects as handles that each hold onto a shared object containing the promised type + a mutex and condition variable for synchronization. When promise::set(T val) is called it seems reasonable to expect that it writes val into the shared state, and and wakes the thread blocked in future<>::wait. This would be standard conformant but generally isn't how it's implemented in the standard libraries. The common implementation is to bundle the value, mutex, and cond_var into the promise. This makes it really easy to introduce race conditions that will often pass tests.. until they don't. Example of most common case: {code} auto foo = std::promise() std::thread async_task([&foo](){ ... do some work ... foo.set_value(1); }) auto future_val = foo.get_future(); int result = future_val.get_value(); {code} That last line has a race between promise::~promise() which happens right after it gets set and any reads of the value, mutex, or condition variable owned by the promise but referenced by the future. When it does show up there will typically be a thread hung in pthread_cond_wait and an invalid 32 bit read of the futex state that the condition variable used under the hood. 2) If a callback happens to throw in an operation that has synchronous shims on top of it the stack will unwind and io_service.run_once will be called to keep getting work done (HDFS-9699). The problem here is that once the stack is unwound there's nothing around to set the promise so the thread blocked on a future will never wake up. The simple/unrealistic fix is to assert that exceptions should never be used but that precludes the use of this library in most C++ projects and the use of most third party dependencies that weren't made by Google. -- This message was sent by Atlassian JIRA (v6.3.15#6346) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-dev-unsubscribe@hadoop.apache.org For additional commands, e-mail: hdfs-dev-help@hadoop.apache.org