Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #81359

Re: condvar-implementation

From "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups comp.lang.c++
Subject Re: condvar-implementation
Date 2021-09-20 15:52 -0700
Organization Aioe.org NNTP Server
Message-ID <sib3bv$q95$1@gioia.aioe.org> (permalink)
References <siakpt$oha$1@dont-email.me>

Show all headers | View raw


On 9/20/2021 11:44 AM, Bonita Montero wrote:
> A long time ago I found a page describing different approaches to imple-
> ment a condvar under Windows, but this would apply to any operating-sys-
> tem having parallelism through supplying semaphores and being designed
> for CPUs with atomic operations.
> I just wrote a special Java-like monitor-object for Win32 and __unix__.
> One speciality with my implementation is, that there's a method to
> signal the monitor (for a single or multiple threads) and relinquish
> ownership in one step. On Windows this only summarizes two atomic ope-
> rations in one, but on __unix__ I increase efficiency by using a SysV
> semaphore set and with semop I can raise two semaphores at once so
> that I save one kernel-call.
> A monitor object has the disadvantage that you can't signal multiple
> states to different threads with it - it's functionally like a single
> mutex bound to a single condvar. So I wrote a dual_monitor class which
> allows bidirectional communications of two threads bound to the same
> mutual exclusion. You cann call notify(_all)( bool b ) on it where b
> is a bool that says which state has to be signalled. Theres no prority
> on either direction and the threads are awakened in an arbitrary order.
> There's also a notify_(all_)and_unlock( bool b ) method that does the
> same signalling and unlocking in one step as for the first monitor.
> 
> But I'm still interested in the paper which describes the different
> approaches in implementing a condvar for Win32. Maybe I can implement
> some improvemehts here also.
> Chris, I _only_ want this paper and no chaotic descriptions, salves
> of chaotic postings, or chaotic sourcecode. Your replies are usually
> no help at all.

Creating a working condvar can be very tricky. Have you tried to run 
your implementation through a race detector? Actually, iirc, using 
explicit waitsets works fine, however, they are bound to SCHED_OTHER.

Take a look at the condvar impl in Pthreads-Win32:

https://sourceware.org/pthreads-win32/

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

condvar-implementation Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-20 20:44 +0200
  Re: condvar-implementation scott@slp53.sl.home (Scott Lurndal) - 2021-09-20 19:54 +0000
  Re: condvar-implementation "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-20 15:52 -0700
    Re: condvar-implementation Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-21 13:24 +0200
      Re: condvar-implementation "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-21 16:08 -0700
        Re: condvar-implementation "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-22 12:37 -0700
          Re: condvar-implementation Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-23 06:18 +0200
            Re: condvar-implementation "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-22 22:23 -0700
              Re: condvar-implementation Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-23 09:09 +0000
                Re: condvar-implementation "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-23 10:28 -0700
              Re: condvar-implementation Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-23 19:06 +0200
            Re: condvar-implementation Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-23 09:07 +0000
              Re: condvar-implementation Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-23 19:07 +0200
      Re: condvar-implementation "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-09-21 16:33 -0700

csiph-web