From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1CB3B3858C5E; Fri, 10 Mar 2023 05:26:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CB3B3858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678426008; bh=zHm3ivW6Hu2xcRiMvRXdkHrrqK+jNTLfjXEc2QSp6p8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oycYnE6SnXDMmJE/mB80uuvXa/eexabvvWFhgMKI8+qm7GZKnU68LUKZvYXk9Uwt0 SvHsrbR2GDgdKXYX1j6f5ho35+ZIUoqXIG4nkBSl2S/Iock+udQntYm8rJTOQ6EK0e M3cRSD4F9cqXUvOhBgRLcnomJ25sJ2nS5KlElCxY= From: "murugesandins at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109074] SIGABRT signal without using -lpthread at Linux RHEL 7.3 Date: Fri, 10 Mar 2023 05:26:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 4.8.5 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: murugesandins at gmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109074 --- Comment #7 from Murugesan Nagarajan --- (In reply to Andrew Pinski from comment #3) > The reason for the abort is because you didn't catch the exception as > libstc++ is throwing one because threads are not enabled at runtime via t= he > linking of libpthread. Thank you again. Handled using try catch exception. However this exception not from my compilation issue. I feel that issue from libstdc++ library(older version) Updated code using try catch exception: /* * Creating thread using "class thread" at C++ * Sample C++ program using the "class thread". * Once an object is created, it used to create a thread. * When creating object, we need to pass the name of the function as parame= ter to that object. * Once creating the object, that function used to be called by the thread. * I will write mutex comments later. * Example: * thread t1(ThreadMethod); * Here t1 is creating the new thread. * I have not tested following code at other operating systems(UNIX/AIX/SunOS/HP-UX/...) excluding Linux, CYGWIN_NT and MINGW */ #include #if defined(LINUX) #include // syscall(SYS_gettid) #ifdef SYS_gettid #define gettid() ((pid_t)syscall(SYS_gettid)) #endif #elif defined(CYGWIN_NT) || defined (MINGW) #define gettid() (unsigned long)pthread_self() #endif #include #include #include using namespace std; int TotalThreadCount =3D 0; pthread_mutex_t mutex =3D PTHREAD_MUTEX_INITIALIZER; void ThreadMethod() { while(true) { if( 2 <=3D TotalThreadCount ) { break; } pthread_mutex_lock(&mutex); string DispTID =3D ""; DispTID =3D string("TotalThreadCount :") + to_string(TotalThreadCount) + " TID: " + to_string(gettid()) + "\n"; cout << DispTID; cout.flush(); sleep(1); ++TotalThreadCount; pthread_mutex_unlock(&mutex); } } int main() { // class thread available from C++11 // initialize the object using related thread function. try { thread t1(ThreadMethod); thread t2(ThreadMethod); t1.join(); t2.join(); } catch( std::exception &e) { cout << "Unable to create thread using class thread\n"; cout << "Caught thread exception: " << e.what() << "\n"; cout << "Re-compile your program using -lpthread\n"; } cout << "mutex.__data: " << (unsigned long long)&mutex.__data << "\= n"; cout << "mutex.__data.__lock: " << (unsigned long long)&mutex.__data.__lock << "\n"; cout << "mutex.__data.__count: " << (unsigned long long)&mutex.__data.__count << "\n"; cout << "mutex.__data.__owner: " << (unsigned long long)&mutex.__data.__owner << "\n"; cout << "mutex.__data.__nusers: " << (unsigned long long)&mutex.__data.__nusers << "\n"; cout << "mutex.__data.__kind: " << (unsigned long long)&mutex.__data.__kind << "\n"; cout << "mutex.__data.__spins: " << (unsigned long long)&mutex.__data.__spins << "\n"; cout << "mutex.__data.__list: " << (unsigned long long)&mutex.__data.__list << "\n"; cout << "mutex.__data.__list.__prev: " << (unsigned long long)&mutex.__data.__list.__prev << "\n"; cout << "mutex.__data.__list.__next: " << (unsigned long long)&mutex.__data.__list.__next << "\n"; cout << "mutex.__size: " << (unsigned long long)&mutex.__size << "\= n"; cout << "mutex.__align: " << (unsigned long long)&mutex.__align << "\n"; return 0; } /* pthread_mutex_t is a union having one struct one char array[40] and one lo= ng. union pthread_mutex_t { pthread_mutex_t::__pthread_mutex_s =3D=3D double linked list { int __lock; =3D=3D 04 bytes unsigned int __count; =3D=3D 04 bytes int __owner; =3D=3D 04 bytes unsigned int __nusers; =3D=3D 04 bytes int __kind; =3D=3D 04 bytes int __spins; =3D=3D 04 bytes __pthread_list_t __list; =3D=3D 16 bytes { *prev; *next; } } __data; =3D=3D 40 bytes char __size[40]; =3D=3D 40 bytes long __align; =3D=3D 08 bytes } =3D=3D 40 bytes since this = is union taking maximum bytes. Hence size of this union is 40 bytes. */ /* $ /usr/bin/g++ -DLINUX -g -Wall thread.cpp -o ./a.out -std=3Dc++11 $ # Tested this code on padding no wastage of memory using mutex. Unable to create thread using class thread Caught thread exception: Enable multithreading to use std::thread: Operation not permitted Re-compile your program using -lpthread mutex.__data: 6316960=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =3D> union mutex.__data.__lock: 6316960 =3D> 6316960, 6316961 6316962 6316963= =20=20=20=20=20=20=20=20 =3D> union mutex.__data.__count: 6316964 =3D> 6316964, 6316965 6316966 6316967 mutex.__data.__owner: 6316968 =3D> 6316968, 6316969 6316970 6316971 mutex.__data.__nusers: 6316972 =3D> 6316972, 6316973 6316974 6316975 mutex.__data.__kind: 6316976 =3D> 6316976, 6316977 6316978 6316979 mutex.__data.__spins: 6316980 =3D> 6316980, 6316981 6316982 6316983 mutex.__data.__list: 6316984 mutex.__data.__list.__prev:6316984 =3D> 6316984,6316985 6316986 6316987 631= 6988 6316989 6316990 6316991 mutex.__data.__list.__next:6316992 =3D> 6316992,6316993 6316994 6316995 631= 6996 6316997 6316998 6316999 mutex.__size: 6316960=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =3D> union mutex.__align: 6316960=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 =3D> union */=