Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

condvar-implementation

48 views
Skip to first unread message

Bonita Montero

unread,
Sep 20, 2021, 2:44:23 PM9/20/21
to
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.

Scott Lurndal

unread,
Sep 20, 2021, 3:54:58 PM9/20/21
to
Bonita Montero <Bonita....@gmail.com> writes:

>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.

Don't ask for help if you don't want answers that don't conform to your
peculiar ideas of how things work.

You might be better off querying a Windows-specific usenet newsgroup
or other resources, if you can't stand to use the C++ language
features defined in <mutex> and <condition_variable>

Chris M. Thomasson

unread,
Sep 20, 2021, 6:52:57 PM9/20/21
to
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/

Bonita Montero

unread,
Sep 21, 2021, 7:24:53 AM9/21/21
to
Am 21.09.2021 um 00:52 schrieb Chris M. Thomasson:

> Creating a working condvar can be very tricky. Have you
> tried to run your implementation through a race detector? ...

Can you read ? I haven't built a condvar but a monitor-object.

Chris M. Thomasson

unread,
Sep 21, 2021, 7:08:52 PM9/21/21
to
I answered the part where you wrote:

Bonita: 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.

You snipped it out.

Chris M. Thomasson

unread,
Sep 21, 2021, 7:34:11 PM9/21/21
to
On 9/21/2021 4:24 AM, Bonita Montero wrote:
A monitor object in C++ seems strange to me.

Chris M. Thomasson

unread,
Sep 22, 2021, 3:37:46 PM9/22/21
to
On 9/21/2021 4:08 PM, Chris M. Thomasson wrote:
> On 9/21/2021 4:24 AM, Bonita Montero wrote:
>> Am 21.09.2021 um 00:52 schrieb Chris M. Thomasson:
>>
>>> Creating a working condvar can be very tricky. Have you
>>> tried to run  your implementation through a race detector? ...
>>
>> Can you read ? I haven't built a condvar but a monitor-object.

Also, can you read the subject of this thread: "condvar-implementation" ?

Bonita Montero

unread,
Sep 23, 2021, 12:18:17 AM9/23/21
to
You were referring to what I implemented so far.
And this wasn't a condvar.

Chris M. Thomasson

unread,
Sep 23, 2021, 1:23:57 AM9/23/21
to
Its been a while Bonita. Heck, last time I used a monitor was WAY back
when I was forced to work on some damn Java code, grrr. I was able to do
the work, but did not really, "enjoy" it so to speak, argh.

Actually, you are making me think back to a god damn horror show I had
to debug where it turned out that somebody thought it was a good idea to
use a condvar, with more than one mutex! My GOD!

Branimir Maksimovic

unread,
Sep 23, 2021, 5:07:51 AM9/23/21
to
condvar assumes way to signal state, and upon receiveing
signal to acquire lock, think about it.

--
7-77-777
\|/
---
/|\

--
/Volumes/air AFP Music Volume/NATASA/temp/peste noire/(2007) Folkfuck Folie/04 - D'un Vilain.mp3

Branimir Maksimovic

unread,
Sep 23, 2021, 5:09:52 AM9/23/21
to
You can implement condvar via semaphore easilly and Windows has semaphores...
Think about it...

Bonita Montero

unread,
Sep 23, 2021, 1:06:51 PM9/23/21
to
Am 23.09.2021 um 07:23 schrieb Chris M. Thomasson:

> Actually, you are making me think back to a god damn horror show I had
> to debug where it turned out that somebody thought it was a good idea to
> use a condvar, with more than one mutex! My GOD!

That's totally different from what I made. And what I made
is a lot of work, but nothing completely difficult in detail.

Bonita Montero

unread,
Sep 23, 2021, 1:07:30 PM9/23/21
to
Am 23.09.2021 um 11:07 schrieb Branimir Maksimovic:
> On 2021-09-23, Bonita Montero <Bonita....@gmail.com> wrote:
>> Am 22.09.2021 um 21:37 schrieb Chris M. Thomasson:
>>> On 9/21/2021 4:08 PM, Chris M. Thomasson wrote:
>>>> On 9/21/2021 4:24 AM, Bonita Montero wrote:
>>>>> Am 21.09.2021 um 00:52 schrieb Chris M. Thomasson:
>>>>>
>>>>>> Creating a working condvar can be very tricky. Have you
>>>>>> tried to run  your implementation through a race detector? ...
>>>>>
>>>>> Can you read ? I haven't built a condvar but a monitor-object.
>>>
>>> Also, can you read the subject of this thread: "condvar-implementation" ?
>>>
>>>
>>>>
>>>> I answered the part where you wrote:
>>>>
>>>> Bonita: 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.
>>>>
>>>> You snipped it out.
>>
>> You were referring to what I implemented so far.
>> And this wasn't a condvar.
>>
> condvar assumes way to signal state, and upon receiveing
> signal to acquire lock, think about it.

That's trivial to understand.

Chris M. Thomasson

unread,
Sep 23, 2021, 1:28:55 PM9/23/21
to
Well... Humm... Way back, a lot of people had condvar impls that are
totally foobar. Not POSIX compliant and, iirc, a lot of them suffered
from the dreaded "lost wakeup" syndrome, from time to time... Afaict,
the really easy way is to use explicit waitsets. However, they have
scheduling issues, sort of bound to SCHED_OTHER...
0 new messages