New to Go. 여러 함수가 작업자처럼 작동하고 데이터 구조를 서로 줄이면서 서로 데이터 구조를 전달하는 "어셈블리 선"을 코딩하려고합니다.Golang의 어셈블리 라인 동시성 사용
type orderStruct struct {
orderNum,capacity int
orderCode uint64
box [9]int
}
func position0(in chan orderStruct){
order := <-in
if((order.orderCode<<63)>>63 == 1){
order.box[order.capacity] = 1
order.capacity += 1
}
fmt.Println(" filling box {", order.orderNum, order.orderCode, order.box, order.capacity, "} at position 0")
}
func startOrder(in chan orderStruct){
order := <-in
fmt.Printf("\nStart an empty box for customer order number %d , request number %d\n", order.orderNum, order.orderCode)
fmt.Println(" starting box {", order.orderNum, order.orderCode, order.box, order.capacity, "}")
d := make(chan orderStruct,1)
go position0(d)
d <- order
}
func main() {
var orders [10]orderStruct
numOrders := len(os.Args)-1
var x int
for i := 0; i < numOrders; i++{
x, _ = strconv.Atoi(os.Args[i+1])
orders[i].orderCode = uint64(x)
orders[i].orderNum = i+1
orders[i].capacity = 0
for j := 0; j < 9; j++{
orders[i].box[j] = 0
}
c := make(chan orderStruct)
go startOrder(c)
c <- orders[i]
}
}
그래서 기본적으로 나는 데 문제가 startOrder에서 인쇄 문() 잘 실행한다는 것입니다,하지만 난) (POSITION0하는 구조체를 통과 할 때, 아무것도 인쇄되지 않습니다. 채널이 어떻게 작동하는지 오해하고 있습니까?
http://blog.golang.org/pipelines를 읽는 것이 좋습니다. 문제가되는 디자인이 두 가지 이상 있습니다. – Momer
(무작위 관찰, 실제 질문의 측면에서 : 나는 한 번 파이프 라인을 병렬로 만들었지 만 명시 적으로 동시 발생하는 부분은 몇 가지''io.Copy (w, r)' '였습니다. 해당 모델에 적합하지만 코드의 상당 부분에서 동시성을 숨길 수 있다면 도움이 될 것입니다.) – twotwotwo