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


Groups > comp.lang.c++ > #81351 > unrolled thread

condvar-implementation

Started byBonita Montero <Bonita.Montero@gmail.com>
First post2021-09-20 20:44 +0200
Last post2021-09-21 16:33 -0700
Articles 14 — 4 participants

Back to article view | Back to comp.lang.c++


Contents

  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

#81351 — condvar-implementation

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-09-20 20:44 +0200
Subjectcondvar-implementation
Message-ID<siakpt$oha$1@dont-email.me>
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.

[toc] | [next] | [standalone]


#81353

Fromscott@slp53.sl.home (Scott Lurndal)
Date2021-09-20 19:54 +0000
Message-ID<dG52J.78756$z%4.17307@fx37.iad>
In reply to#81351
Bonita Montero <Bonita.Montero@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>

[toc] | [prev] | [next] | [standalone]


#81359

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-09-20 15:52 -0700
Message-ID<sib3bv$q95$1@gioia.aioe.org>
In reply to#81351
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/

[toc] | [prev] | [next] | [standalone]


#81368

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-09-21 13:24 +0200
Message-ID<sicfdr$dca$1@dont-email.me>
In reply to#81359
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.

[toc] | [prev] | [next] | [standalone]


#81398

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-09-21 16:08 -0700
Message-ID<sidolg$14i7$1@gioia.aioe.org>
In reply to#81368
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.

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.

[toc] | [prev] | [next] | [standalone]


#81429

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-09-22 12:37 -0700
Message-ID<sig0m0$1nni$1@gioia.aioe.org>
In reply to#81398
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.

[toc] | [prev] | [next] | [standalone]


#81438

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-09-23 06:18 +0200
Message-ID<sigv5v$cad$1@dont-email.me>
In reply to#81429
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.

[toc] | [prev] | [next] | [standalone]


#81439

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-09-22 22:23 -0700
Message-ID<sih313$u2a$1@gioia.aioe.org>
In reply to#81438
On 9/22/2021 9:18 PM, Bonita Montero 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.
> 

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!

[toc] | [prev] | [next] | [standalone]


#81451

FromBranimir Maksimovic <branimir.maksimovic@gmail.com>
Date2021-09-23 09:09 +0000
Message-ID<qvX2J.31504$6u6.7496@fx03.iad>
In reply to#81439
On 2021-09-23, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
> On 9/22/2021 9:18 PM, Bonita Montero 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.
>> 
>
> 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!
You can implement condvar via semaphore easilly and Windows has semaphores...
Think about it...

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

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

[toc] | [prev] | [next] | [standalone]


#81479

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-09-23 10:28 -0700
Message-ID<siidgb$t2e$1@gioia.aioe.org>
In reply to#81451
On 9/23/2021 2:09 AM, Branimir Maksimovic wrote:
> On 2021-09-23, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
>> On 9/22/2021 9:18 PM, Bonita Montero 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.
>>>
>>
>> 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!
> You can implement condvar via semaphore easilly and Windows has semaphores...
> Think about it...

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

[toc] | [prev] | [next] | [standalone]


#81474

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-09-23 19:06 +0200
Message-ID<siic71$mcv$1@dont-email.me>
In reply to#81439
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.

[toc] | [prev] | [next] | [standalone]


#81450

FromBranimir Maksimovic <branimir.maksimovic@gmail.com>
Date2021-09-23 09:07 +0000
Message-ID<xtX2J.31503$6u6.14336@fx03.iad>
In reply to#81438
On 2021-09-23, Bonita Montero <Bonita.Montero@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.

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

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

[toc] | [prev] | [next] | [standalone]


#81475

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-09-23 19:07 +0200
Message-ID<siic88$mcv$2@dont-email.me>
In reply to#81450
Am 23.09.2021 um 11:07 schrieb Branimir Maksimovic:
> On 2021-09-23, Bonita Montero <Bonita.Montero@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.

[toc] | [prev] | [next] | [standalone]


#81400

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2021-09-21 16:33 -0700
Message-ID<sidq58$1k43$1@gioia.aioe.org>
In reply to#81368
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.

A monitor object in C++ seems strange to me.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web