Update: nope, I was wrong. Those two scenarios cannot happen. Because 
reading the one
value in cc.ready acts as a mutex already.

On Sunday, January 21, 2024 at 5:08:35 PM UTC+1 Jason E. Aten wrote:

> I like this question, as a fun puzzle to solve. Bryan's approach is 
> similar to how I am thinking about it.
>
> Reading his code (https://go.dev/play/p/BpLBYsSSqn2?v=gotip), however, I 
> think there are some issues:
>
> 1) What if there are two simultaneous calls to Broadcast that end up 
> closing the
> same channel (on line 46) twice?  A panic would ensue due to the double 
> close. (I've long
> felt that this was a poor choice in Go's channel design, a double close 
> should really be fine -- the
> current design means that you almost always have to protect a close() 
> with a separate mutex, and check if the close has already happened first).
>
> 2) What Signal and Broadcast are called at the same time, and the lines 
> are interleaved
> 36, 45, 46, 38: you would get a panic from trying to send on a closed 
> channel, right?
>
> On Thursday, January 18, 2024 at 5:23:45 PM UTC+1 Bryan C. Mills wrote:
>
>> Now with tests (copied from 
>> https://cs.opensource.google/go/go/+/master:src/sync/cond_test.go;drc=4a3071696ddfb13e1a8f35f76197b7b3143492f4
>> ):
>> https://go.dev/play/p/BpLBYsSSqn2?v=gotip
>>
>> On Wednesday, January 17, 2024 at 5:38:18 PM UTC-5 Bryan C. Mills wrote:
>>
>>> Perhaps something like this:
>>> https://go.dev/play/p/wllkgRAtd4a
>>>
>>> Disclaimer: not yet tested, probably contains bugs.
>>> Also, I strongly _disrecommend_ the use of condition variables, because 
>>> they're too bug-prone. 🙃
>>>
>>> On Friday, January 12, 2024 at 2:48:09 PM UTC-5 Rochus Keller wrote:
>>>
>>>> > Something like this? https://go.dev/play/p/_H3kFjprAGG
>>>>
>>>> No, sorry. The goal is to emulate a full monitor just with channels, as 
>>>> demonstrated in the referenced text (see the Stack example). The Mutex is 
>>>> likely correct, but the Signal has yet to pass the scrutinity of the folks 
>>>> here.
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ad4b5dd4-aa29-4d89-9de4-088eef3984bdn%40googlegroups.com.

Reply via email to