Hello Kai and Vadim! On Wed, Sep 11, 2013 at 10:39 PM, Kai Tietz <> wrote: > Hi, > > 2013/9/12 Vadim <>: >> Hi, >> I am investigating performance problems in binary compiled with mingw-w64, >> and libwinpthreads mutex comes at the top of my profile. >> Looking at the code, it appears as if mutexes are implemented using Windows >> semaphores? Is this right? > Yes, that is right. >> Does anybody know why critical sections weren't used instead? > It is a while ago, but AFAIR this is reasoned by the fact that > pthread-mutexes have 3 different flavors. First recursive, > thread-owned, and non-thread-owned. First and second can > beimplemented by a critical section, the third (and standard-variant) > can't that easily. Additional it is required - we didn't implement > this feature until now in winpthread - that there are named variants. > >> Vadim
Just some background comments -- not directly relevant to mingw-w64: Windows semaphores are (as are windows mutexes) interprocess synchronization objects, that is, they can be used to synchronize different processes, not just different threads of the same process. As such, they are somewhat heavy weight. In contrast, windows critical sections are purely intraprocess, so they are lighter, and, if you are only working with threads in a single process, generally more efficient. I experimented with using both windows mutexes and windows critical sections for implementing std::thread with mingw-w64; not surprisingly, the critical-section version was significantly faster, at least when it came to creating a lot of std::mutex objects. (Please note, that my goal was to implement std::thread, not pthreads, so the specific needs of pthreads were not relevant for my experiment.) Two down-sides I found with windows critical sections: They are relatively recent -- I think Vista and later. (I didn't really care about this.) Also, the windows threading api does not support a timed wait on a windows critical section (it does on a windows mutex), so I had to resort to some hackery to get std::timed_mutex::try_lock_for() and related to work with the critical-section implementation. (Note that std::mutex and std::timed_mutex are different types, so, in principle, one could implement std::mutex with windows critical sections and std::timed_mutex with windows mutexes. But to me it seemed that the extra cost of windows mutexes outweighed the hackery needed for the critical-section solution.) > Kai Happy Pthreads Hacking! K. Frank ------------------------------------------------------------------------------ How ServiceNow helps IT people transform IT departments: 1. Consolidate legacy IT systems to a single system of record for IT 2. Standardize and globalize service processes across IT 3. Implement zero-touch automation to replace manual, redundant tasks http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
