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 {
...
@@ -75,49 +75,22 @@ func mkdch2() *dch2 {
// generation to begin servicing out[1].
// generation to begin servicing out[1].
func
dosplit
(
in
*
dch
,
out
*
dch2
,
wait
*
chan
int
){
func
dosplit
(
in
*
dch
,
out
*
dch2
,
wait
*
chan
int
){
//print "dosplit ", wait, "\n";
var
t
*
dch
;
var
t
*
dch
;
both
:=
false
;
// do not service both channels
both
:=
false
;
// do not service both channels
/*
select
{
select
{
case
<-
out
[
0
]
.
req
:
case
<-
out
[
0
]
.
req
:
;
;
case
<-
wait
:
case
<-
wait
:
both =
1
;
both
=
true
;
select
{
select
{
case
<-
out
[
0
]
.
req
:
case
<-
out
[
0
]
.
req
:
;
;
case
<-
out
[
1
]
.
req
:
case
<-
out
[
1
]
.
req
:
t
=
out
[
0
];
out
[
0
]
=
out
[
1
];
out
[
1
]
=
t
;
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
++
;
seqno
++
;
in
.
req
-<
seqno
;
in
.
req
-<
seqno
;
release
:=
new
(
chan
int
);
release
:=
new
(
chan
int
);
...
@@ -165,42 +138,21 @@ func getn(in *[]*dch, n int) *[]item {
...
@@ -165,42 +138,21 @@ func getn(in *[]*dch, n int) *[]item {
}
}
for
n
=
2
*
n
;
n
>
0
;
n
--
{
for
n
=
2
*
n
;
n
>
0
;
n
--
{
seqno
++
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
select
{
sel
:
case
req
[
0
]
-<
seqno
:
for
c1
:=
0
;
;
c1
++
{
dat
[
0
]
=
in
[
0
]
.
dat
;
for
i
:=
0
;
i
<
2
;
i
++
{
req
[
0
]
=
nil
;
ok
:=
false
;
case
req
[
1
]
-<
seqno
:
if
req
[
i
]
!=
nil
{
ok
=
req
[
i
]
-<
seqno
}
dat
[
1
]
=
in
[
1
]
.
dat
;
if
ok
{
req
[
1
]
=
nil
;
dat
[
i
]
=
in
[
i
]
.
dat
;
case
it
<-
dat
[
0
]
:
req
[
i
]
=
nil
;
out
[
0
]
=
it
;
goto
OUT
;
// BUG
dat
[
0
]
=
nil
;
break
sel
;
case
it
<-
dat
[
1
]
:
}
out
[
1
]
=
it
;
ok
=
false
;
dat
[
1
]
=
nil
;
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
();
}
}
OUT
:
}
}
return
out
;
return
out
;
}
}
...
@@ -251,7 +203,6 @@ func mkPS2() *dch2 {
...
@@ -251,7 +203,6 @@ func mkPS2() *dch2 {
func
gcd
(
u
,
v
int64
)
int64
{
func
gcd
(
u
,
v
int64
)
int64
{
if
u
<
0
{
return
gcd
(
-
u
,
v
)
}
if
u
<
0
{
return
gcd
(
-
u
,
v
)
}
if
u
>
v
{
return
gcd
(
v
,
u
)
}
if
u
==
0
{
return
v
}
if
u
==
0
{
return
v
}
return
gcd
(
v
%
u
,
u
)
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