Fork me on GitHub
#core-async
<
2017-03-03
>
tbaldridge14:03:18

what's strange is that it works about 1/2 of the time

vinai14:03:58

Thanks for taking a look, @tbaldridge I get very inconsistent results. Like, just now:

:b read true
:b read true
hu?

vinai14:03:02

:b read :to-write
:a read :to-write
or any combination. But I never get a wrote something in the log.

vinai14:03:12

For you it works sometimes even?

dergutemoritz15:03:23

That true looks like it should never end up there ...

tbaldridge15:03:59

yeah, I'm really sure there's a bug here somewhere

tbaldridge15:03:58

what's really odd is that it happens with thread and alt!! as well

dergutemoritz15:03:08

Also happens when giving c a buffer

bronsa15:03:15

@tbaldridge maybe there's a bug in do-alt then?

bronsa15:03:29

does >! return true?

vinai15:03:05

Unless the channel is closed.

tbaldridge15:03:18

yeah, I think the issue is related to this: "Each option may appear at most once. The choice and parking characteristics are those of alts!"

tbaldridge15:03:09

notice how nothing ever writes. This is because we're using the same channel twice, and I think the macro is doing some sort of indexing or grouping based on the channel

tbaldridge15:03:21

and the code is being mixed up with a different op

bronsa15:03:51

mhh I read that "each option may appear at most once" as (alt! c 43 c 42) not being allowed, not not allowing either a take or a put to the same channel

bronsa15:03:15

but maybe you're right

tbaldridge15:03:19

same here, but the behavior fits

bronsa15:03:37

wonder what appens if we (let [w c]

tbaldridge15:03:23

watch what happens if you increase the "dotimes [x 2]" to 4 😉

tbaldridge15:03:47

in one of my tests it printed 4 log messages

vinai15:03:50

Yeah. Did that, too.

bronsa15:03:34

that with go or thread?

bronsa15:03:40

i only get 2 and wait with thread

vinai15:03:03

I get more if I increase the buffer of log accordingly.

vinai15:03:07

Each option may appear at most once. is only stated in regards to alt!. I guess I could try alts! then, even though that wouldn't look as nice.

tbaldridge15:03:47

But I do need to say this...this is some wacky code. Writing and reading to the same channel from the same thread isn't a pattern that happens in production code.

vinai15:03:01

I was trying to port the go-lang chatroulette example to Clojure: https://engineering.tumblr.com/post/23049359840/talk-by-andrew-gerrand-go-code-that-grows-with (about minute 19 in the video)

vinai15:03:40

He uses that in there to match connections.

vinai15:03:16

By the way, no luck using alts!. Same wacky inconsistent behavior.

tbaldridge15:03:54

heh, I just realized something....I haven't a clue how this works with the implementation of channels....

bronsa15:03:45

i'm looking at the macroexpansion of alt!

bronsa15:03:02

it 100% gets confused if you take and write to the same channel

bronsa15:03:06

boils down to (let [c (chan)] (alts!! [c [c :w]]))

vinai15:03:15

Since alts! shows the same behavior it must go deeper than the alt! macro.

tbaldridge15:03:45

I think it might be at the channel level

bronsa15:03:47

that sometimes returns true, sometimes return :w

tbaldridge15:03:20

So here's how a channel works: If you put, the op locks the put handler and the channel. Then it looks for a take, if it finds a take it locks the take handler, then it commits the put and the take, and dispatches the values through the put and take handlers.

tbaldridge15:03:00

In an alt! all the branches share the same handler. So in that case the put and the take hander are the same handler. But all the semantics of the handler are commit/deliver once.

bronsa15:03:11

very weird edge case

vinai16:03:27

You have no idea how excited that makes me feel. I'm such a fanboy.

tbaldridge16:03:15

Well you stumped me and bronsa, so (thumbsup) for that one 🙂

tbaldridge16:03:44

It'll probably be awhile before I hear back from Rich, and I'm 90% sure the answer is "don't do that", but I'm interested in hearing if he agrees with my theory

vinai16:03:20

I must admit that it looked like a clever bit of code in the go-lang example. Now I have to come up with a different way to do the connection pairing 🙂

tbaldridge16:03:01

Yeah go seems fond of that sort of stuff for some reason

tbaldridge16:03:04

Apparently writing to a channel then reading from that same channel is a pattern in go-lang

vinai16:03:26

Um... sounds like let

vinai16:03:00

A complicated let

dergutemoritz16:03:57

Nice detective work!