This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"strconv" | |
"sync" | |
"time" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description: Hyper-V Sockets | |
srcversion: 4EC78A1B60598CC0FEB9FC2 | |
name: hv_sock | |
description: Microsoft Hyper-V network driver | |
srcversion: 852146352704FB30084A3F3 | |
name: hv_netvsc | |
description: Hyper-V Utilities | |
srcversion: 3B8AC762BA4858730251E7E |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
Exploring goroutine ordering imposed by runtime scheduling. The | |
situation encoded below consists of a single synchronous writer and two | |
concurrent readers. The readers are connected to the writer via a single | |
unbuffered shared channel. A | |
selection of "next" goroutine from runtime scheduling queue. Trying | |
to enforce "fairness" whose meaning in this situation guarantees execution | |
of all goroutines, avoiding goroutine starvation/barging explained |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
Exploring concept of "Happens Before" using channels to impose order on | |
selection of "next" goroutine from runtime scheduling queue. Trying | |
to enforce "fairness" whose meaning in this situation guarantees execution | |
of all goroutines, avoiding goroutine starvation/barging explained | |
here: https://github.com/golang/go/issues/11506. | |
go PlayGound: https://play.golang.org/p/4sGKDepzqaV | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func consumeOrderedByAffectingProbability(msg_1ch chan msg_1, msg_2ch chan msg_2) { | |
// implement priorty function that selects messages from msg_2ch twice as often | |
// as msg_1ch by affecting the probability function of the select | |
// statement. produces outcome whose message type totals are equivalent to | |
// nil bias function but using simpler encoding. | |
for msgCnt := 0; msgCnt < 21; msgCnt++ { | |
select { | |
case msg, ok := <-msg_1ch: | |
if ok { | |
msg.msgType() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type msg_1 struct { | |
} | |
func (msg_1) msgType() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func consumeAccordingToChannelSemantics(msg_1ch chan msg_1, msg_2ch chan msg_2) { | |
// because the channels were asychronous and completely full | |
// before running this routine, select's channel semantics | |
// considers the messages as having arrived at the same time. | |
// select therefore randomly reads one of the channels. since | |
// only two case statements, probability of selection is | |
// equivalent to a random coin toss. | |
for msgCnt := 0; msgCnt < 21; msgCnt++ { | |
select { | |
case msg, ok := <-msg_1ch: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func consumeOrderedByBias(msg_1ch chan msg_1, msg_2ch chan msg_2) { | |
// copy channels to enable their restoration | |
msg_1_save := msg_1ch | |
msg_2_save := msg_2ch | |
// bias function encoded as a for loop | |
for msgCnt := 0; msgCnt < 21; msgCnt++ { | |
// use modulus math to help implement bias function | |
if msgCnt%3 == 0 { | |
// favor channel 1 when processing muliples of 3 |
NewerOlder