Possiblly bug of cygwin1.dll
Takashi Yano
takashi.yano@nifty.ne.jp
Sun Jan 21 11:10:51 GMT 2024
Hi Corinna,
On Sat, 20 Jan 2024 21:24:27 +0900
Takashi Yano wrote:
> On Sat, 20 Jan 2024 10:13:22 +0100
> ASSI wrote:
> > Takashi Yano via Cygwin writes:
> > > I might find the culprit in gcc's libstdc++ code such as:
> > > libstdc++-v3/include/ext/concurrentce.h:
> > > class __mutex
> > > {
> > > private:
> > > #if __GTHREADS && defined __GTHREAD_MUTEX_INIT
> > > __gthread_mutex_t _M_mutex = __GTHREAD_MUTEX_INIT;
> > > #else
> > > __gthread_mutex_t _M_mutex;
> > > #endif
> > >
> > > __GTHREAD_MUTEX_INIT here is PTHREAD_MUTEX_INITIALIZER and
> > > __gthread_mutex_t is pthread_mutex_t.
> > >
> > > I think this code vaiolates the POSIX statement.
> >
> > So what happens if you undefine __GTHREAD_MUTEX_INIT?
>
> I have tried. The test case:
> #include <mutex>
> int main()
> {
> for (;;) {
> std::mutex *m = new std::mutex;
> m->lock();
> m->unlock();
> delete m;
> }
> return 0;
> }
> gets working fine. However, this test case:
> #include <future>
> int func() { return 0; }
> int main()
> {
> for (;;) {
> std::future<int> f = std::async(std::launch::async, func);
> f.get();
> }
> return 0;
> }
> still has the problem.
>
> pthread_mutex_t might be initialized also at another place...
I found the cause. In pthread.h of cygwin, PTHREAD_ONCE_INIT is defined as:
#define PTHREAD_ONCE_INIT { PTHREAD_MUTEX_INITIALIZER, 0 }
however, libstdc++ initializes non-static pthread_once_t using this macro.
I cannot find the POSIX statement that only static pthread_once_t can be
initialized using PTHREAD_ONCE_INIT. If I do not overlook something,
this is the problem of cygwin side, isn't it?
--
Takashi Yano <takashi.yano@nifty.ne.jp>
More information about the Cygwin
mailing list