Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
9c8f48bd
Commit
9c8f48bd
authored
Jul 28, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use real select
R=ken OCL=13519 CL=13519
parent
3835e01d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
64 deletions
+15
-64
powser1.go
test/chan/powser1.go
+15
-64
No files found.
test/chan/powser1.go
View file @
9c8f48bd
...
...
@@ -75,49 +75,22 @@ func mkdch2() *dch2 {
// generation to begin servicing out[1].
func
dosplit
(
in
*
dch
,
out
*
dch2
,
wait
*
chan
int
){
//print "dosplit ", wait, "\n";
var
t
*
dch
;
both
:=
false
;
// do not service both channels
/*
select
{
case
<-
out
[
0
]
.
req
:
;
case
<-
wait
:
both =
1
;
both
=
true
;
select
{
case
<-
out
[
0
]
.
req
:
;
case
<-
out
[
1
]
.
req
:
t
=
out
[
0
];
out
[
0
]
=
out
[
1
];
out
[
1
]
=
t
;
};
}
*/
// select simulation
for
{
var
ok
bool
;
var
dummy
int
;
dummy
,
ok
=
<-
out
[
0
]
.
req
;
if
ok
{
goto
OUT1
}
dummy
,
ok
=
<-
wait
;
if
ok
{
both
=
true
;
// select simulation
for
{
dummy
,
ok
=
<-
out
[
0
]
.
req
;
if
ok
{
goto
OUT1
}
dummy
,
ok
=
<-
out
[
1
]
.
req
;
if
ok
{
out
[
0
],
out
[
1
]
=
out
[
1
],
out
[
0
];
goto
OUT1
}
sys
.
gosched
();
}
}
sys
.
gosched
();
}
OUT1
:
//BUG
seqno
++
;
in
.
req
-<
seqno
;
release
:=
new
(
chan
int
);
...
...
@@ -165,42 +138,21 @@ func getn(in *[]*dch, n int) *[]item {
}
for
n
=
2
*
n
;
n
>
0
;
n
--
{
seqno
++
/*
select{
case req[i=] <-= seqno:
dat[i] = in[i].dat;
req[i] = nil;
case it = <-dat[i=]:
out[i] = it;
dat[i] = nil;
}
*/
// simulation of select
sel
:
for
c1
:=
0
;
;
c1
++
{
for
i
:=
0
;
i
<
2
;
i
++
{
ok
:=
false
;
if
req
[
i
]
!=
nil
{
ok
=
req
[
i
]
-<
seqno
}
if
ok
{
dat
[
i
]
=
in
[
i
]
.
dat
;
req
[
i
]
=
nil
;
goto
OUT
;
// BUG
break
sel
;
}
ok
=
false
;
if
dat
[
i
]
!=
nil
{
it
,
ok
=
<-
dat
[
i
]
}
if
ok
{
out
[
i
]
=
it
;
dat
[
i
]
=
nil
;
goto
OUT
;
// BUG
break
sel
;
}
sys
.
gosched
();
}
sys
.
gosched
();
select
{
case
req
[
0
]
-<
seqno
:
dat
[
0
]
=
in
[
0
]
.
dat
;
req
[
0
]
=
nil
;
case
req
[
1
]
-<
seqno
:
dat
[
1
]
=
in
[
1
]
.
dat
;
req
[
1
]
=
nil
;
case
it
<-
dat
[
0
]
:
out
[
0
]
=
it
;
dat
[
0
]
=
nil
;
case
it
<-
dat
[
1
]
:
out
[
1
]
=
it
;
dat
[
1
]
=
nil
;
}
OUT
:
}
return
out
;
}
...
...
@@ -251,7 +203,6 @@ func mkPS2() *dch2 {
func
gcd
(
u
,
v
int64
)
int64
{
if
u
<
0
{
return
gcd
(
-
u
,
v
)
}
if
u
>
v
{
return
gcd
(
v
,
u
)
}
if
u
==
0
{
return
v
}
return
gcd
(
v
%
u
,
u
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment