From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 3E35A3894C1D for ; Tue, 18 Aug 2020 18:16:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3E35A3894C1D Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-43-1UN5tnvvNl6A04hj1s33lw-1; Tue, 18 Aug 2020 14:16:01 -0400 X-MC-Unique: 1UN5tnvvNl6A04hj1s33lw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E18B1084C82; Tue, 18 Aug 2020 18:16:00 +0000 (UTC) Received: from localhost (unknown [10.33.36.183]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCCF87BE70; Tue, 18 Aug 2020 18:15:59 +0000 (UTC) Date: Tue, 18 Aug 2020 19:15:58 +0100 From: Jonathan Wakely To: Lewis Hyatt Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH] libstdc++: testsuite: Address random failure in pthread_create() [PR54185] Message-ID: <20200818181558.GG3400@redhat.com> References: <20200813221536.GA51547@ldh-imac.local> <20200818084331.GD3400@redhat.com> <20200818152040.GA25142@ldh-imac.local> MIME-Version: 1.0 In-Reply-To: <20200818152040.GA25142@ldh-imac.local> X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Aug 2020 18:16:07 -0000 On 18/08/20 11:20 -0400, Lewis Hyatt wrote: >On Tue, Aug 18, 2020 at 09:43:31AM +0100, Jonathan Wakely wrote: >> On 13/08/20 18:15 -0400, Lewis Hyatt via Libstdc++ wrote: >> > Hello- >> > >> > The attached patch was discussed briefly on PR 54185 here: >> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54185#c14 >> > The test case for this PR sometimes fails due to random failures in >> > pthread_create() that are not related to the original PR. This patch fixes >> > it up by ignoring those failures. The test case was designed to repeat the >> > same test 1000 times to attempt to reproduce a race condition, so I think is >> > OK if some of those iterations are simply skipped. >> > >> > Thanks for taking a look at it; I can commit it if it makes sense. >> > >> > -Lewis >> >> > libstdc++: testsuite: Address random failure in pthread_create() [PR54185] >> > >> > The test for this PR calls pthread_create() many times in a row, which may fail >> > with EAGAIN sometimes. Avoid generating a test failure in this case. >> > >> > libstdc++-v3/ChangeLog: >> > >> > PR libstdc++/54185 >> > * testsuite/30_threads/condition_variable/54185.cc: Make test robust >> > to random pthread_create() failures. >> >> Thanks for the patch. It certainly looks reasonable, but I wonder if >> the attached version wouldn't be (very slightly) better. The >> difference is that instead of just giving up at the first EAGAIN we >> keep trying. This way we might be able to create a few more threads >> before the loop finishes. If we still keep failing, it works the same. >> >> I've also added a check that the failures are due to EAGAIN, and we'll >> still terminate if there's some other problem. I'm assuming that your >> failures are EAGAIN. Do you know why that's happening? Does your >> system a low value for RLIMIT_NPROC or something? >> > >Right, good point to check for EAGAIN. Yes, that's the error I get. I don't >understand why it happens. It's not related to libstdc++, I can reproduce it >with the below: > >====== >#include >void* do_nothing (void*) >{ > return nullptr; >} >int main () { > for (int i = 0; i != 1000; ++i) > { > for (int j = 0; j != 10; ++j) > { > pthread_t thread; > const int err = pthread_create (&thread, nullptr, do_nothing, nullptr); > if (err) return 1; > pthread_join (thread, nullptr); > } > } >} >====== > >If I run this just once at a time, it never fails. But if I run it twice at >a time, it fails about 30% of the time, like: >root@host:/home/lewis# (./pthread_fail || echo ERR) & \ > (./pthread_fail || echo ERR) & wait >[1] 25041 >[2] 25042 >ERR >ERR > >All the rlimits are infinite or as high as possible, but I dug around a bit >and it seems this is a systemd thing, this system had systemd-logind >disabled (perhaps not in the correct way) and something about the >configuration led to the issue. Enabling systemd-logind resolves it for >me. So perhaps this was mostly specific to me. Sorry if I wasted your >time... if you still think it's worth doing something here I am happy to >help. I don't think it's a waste of time. Adding the 'notified' variable to the test to prevent spurious wakeups is an improvement if nothing else. >FWIW, regarding your extension to the patch, in case there are some >legitimate thread creation problems, one thing to keep in mind is that the >retrying after failure makes certain things worse. For instance, (with my >system in the previous state), what would happen is the 54185.cc hit the >pthread_create failure, then prior to this patch it just bailed out. With >either of these patches it tries more times, which can worsen issues in >unrelated test cases running in parallel, that may see random failures in >their own forks or thread creations. This test case is trying hard to >reproduce the race condition by running 1000 iterations, which seems >worthwhile given it's still failing on some systems like AIX, but on the On AIX it fails even with one iteration (not 1000) i.e. you simply can't destroy a pthread_cond_t while there are threads still waiting on it. We don't need 1000 iterations to hit that bug, it happens right away. >other hand it's possible doing 50 instead of 1000 would work too, and be >less prone to unrelated resource issues. Maybe. I'm a bit concerned that if the test started consistently breaking out of the inner loop after one or two threads on everybody's systems it would never actually try to delete a condition_variable that is being waited on. And so it would never exercise the problem case, and we'd never know. The test would PASS with no indication of problems, but wouldn't actually test anything. So I think I'd like it to keep trying to create threads. The meaning of EAGAIN is "try again" after all :-) >Thanks for taking a look at this.