Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unbuffered channel #21

Merged
merged 4 commits into from
Apr 4, 2024
Merged

feat: unbuffered channel #21

merged 4 commits into from
Apr 4, 2024

Conversation

shenyih0ng
Copy link
Owner

@shenyih0ng shenyih0ng commented Apr 4, 2024

Description

This PR implements unbuffered channel support for the Go ECE. For an unbuffered channel, the sender blocks until the receiver has received the value (https://go.dev/doc/effective_go#channels).

Implementation Details

  1. An unbuffered channel in the Go ECE is represented using 2 words (2*8 = 16 bytes) including the tagged pointer

    • We store the ids of the sender and receiver goroutines in the tagged pointer, each occupying 2 bytes, hence we are assuming an upper bound of 2^16 goroutines in total
    • The one word (8 bytes) that follows the tagged pointer will be used as a slot for senders to send to and receivers to receive from
    • We also use 1 byte in the tagged pointer to track if there is a sync process happening
      • More details of what the sync process is can be found in the UnbufferedChannel implementation (i've left a bunch of comments to explain the behaviour)
  2. Unlike the actual implementation of channels in go (https://docs.google.com/document/d/1yIAYmbvL3JxOKOjuCyon7JhW4cSv1wy5hC0ApeGMV9s/pub) that relies on mutexes, I opted to model channels as its own independent construct. This means that the unbuffered channel itself is responsible for signalling/blocking goroutines.

@shenyih0ng shenyih0ng self-assigned this Apr 4, 2024
@shenyih0ng shenyih0ng changed the title Feat/unbuffered channel feat: unbuffered channel Apr 4, 2024
@shenyih0ng shenyih0ng requested a review from alvynben April 4, 2024 10:54
@shenyih0ng shenyih0ng merged commit 35606b5 into master Apr 4, 2024
1 check passed
@shenyih0ng shenyih0ng deleted the feat/unbuffered-channel branch April 4, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant