From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129617 invoked by alias); 12 Feb 2018 13:30:21 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 128324 invoked by uid 89); 12 Feb 2018 13:30:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=native_handle X-HELO: hqemgate15.nvidia.com Received: from hqemgate15.nvidia.com (HELO hqemgate15.nvidia.com) (216.228.121.64) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Feb 2018 13:30:03 +0000 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com id ; Mon, 12 Feb 2018 05:30:06 -0800 Received: from HQMAIL101.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 12 Feb 2018 05:30:02 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 12 Feb 2018 05:30:02 -0800 Received: from UKMAIL102.nvidia.com (10.26.138.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 12 Feb 2018 13:30:01 +0000 Received: from localhost.localdomain (10.21.45.12) by UKMAIL102.nvidia.com (10.26.138.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 12 Feb 2018 13:29:57 +0000 To: GDB Development From: Dmitry Antipov Subject: Printing thread_local a.k.a. __thread variables Message-ID: <780169f5-fa63-3357-ed78-a3045991c307@nvidia.com> Date: Mon, 12 Feb 2018 13:30:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1473B9A5B3EBCFC8C4FB6364" X-ClientProxiedBy: UKMAIL102.nvidia.com (10.26.138.15) To UKMAIL102.nvidia.com (10.26.138.15) X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00082.txt.bz2 --------------1473B9A5B3EBCFC8C4FB6364 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 214 I just tried the recent git snapshot (on x86 GNU/Linux) and always seeing 100 for 'tlocal' variable. Compiled wit GCC 7.3, -O0 -g3, regardless of -gdwarf-4 default or -gdwarf-5. Am I doing wrong something? Dmitry --------------1473B9A5B3EBCFC8C4FB6364 Content-Type: text/x-c++src; name="t-thread.cc" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="t-thread.cc" Content-length: 1194 #include #include #include #include #include #include #include int depth; thread_local int tlocal = 100; void bp1 (int t, int level, int n) { auto r = std::rand () % (t + level + n); std::this_thread::sleep_for (std::chrono::milliseconds (r)); printf ("bp1 in thread %d: %d\n", t, tlocal); } void bp2 (int t, int level, int n) { auto r = std::rand () % (t + level + n); std::this_thread::sleep_for (std::chrono::milliseconds (r)); printf ("bp2 in thread %d: %d\n", t, tlocal); } void sleeper (int t, int level, int n) { int loop = 0; if (++level < depth) sleeper (t, level, n); else while (true) { if (++loop % 2) bp1 (t, level, n); else bp2 (t, level, n); tlocal += t + 1; } } int main (int argc, char *argv[]) { auto max = argc > 1 ? std::atoi (argv[1]) : 8; depth = argc > 2 ? std::atoi (argv[2]) : 16; std::vector T; for (auto i = 0; i < max; i++) { auto t = new std::thread (sleeper, i, 0, 1000); pthread_setname_np (t->native_handle (), "worker"); T.push_back (t); } for (auto &t: T) t->join (); return 0; } --------------1473B9A5B3EBCFC8C4FB6364--