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
d2117ad4
Commit
d2117ad4
authored
Jan 24, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make test/chan/nonblock work even with real os threads
R=ken OCL=23422 CL=23422
parent
d8819569
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
33 deletions
+62
-33
nonblock.go
test/chan/nonblock.go
+62
-33
No files found.
test/chan/nonblock.go
View file @
d2117ad4
...
...
@@ -9,40 +9,55 @@
package
main
func
pause
()
{
for
i
:=
0
;
i
<
100
;
i
++
{
sys
.
Gosched
()
}
}
import
"time"
func
i32receiver
(
c
chan
int32
)
{
func
i32receiver
(
c
chan
int32
,
strobe
chan
bool
)
{
if
<-
c
!=
123
{
panic
(
"i32 value"
)
}
strobe
<-
true
}
func
i32sender
(
c
chan
int32
)
{
c
<-
234
func
i32sender
(
c
chan
int32
,
strobe
chan
bool
)
{
c
<-
234
;
strobe
<-
true
}
func
i64receiver
(
c
chan
int64
)
{
func
i64receiver
(
c
chan
int64
,
strobe
chan
bool
)
{
if
<-
c
!=
123456
{
panic
(
"i64 value"
)
}
strobe
<-
true
}
func
i64sender
(
c
chan
int64
)
{
c
<-
234567
func
i64sender
(
c
chan
int64
,
strobe
chan
bool
)
{
c
<-
234567
;
strobe
<-
true
}
func
breceiver
(
c
chan
bool
)
{
func
breceiver
(
c
chan
bool
,
strobe
chan
bool
)
{
if
!
<-
c
{
panic
(
"b value"
)
}
strobe
<-
true
}
func
bsender
(
c
chan
bool
)
{
c
<-
true
func
bsender
(
c
chan
bool
,
strobe
chan
bool
)
{
c
<-
true
;
strobe
<-
true
}
func
sreceiver
(
c
chan
string
)
{
func
sreceiver
(
c
chan
string
,
strobe
chan
bool
)
{
if
<-
c
!=
"hello"
{
panic
(
"s value"
)
}
strobe
<-
true
}
func
ssender
(
c
chan
string
,
strobe
chan
bool
)
{
c
<-
"hello again"
;
strobe
<-
true
}
func
ssender
(
c
chan
string
)
{
c
<-
"hello again"
var
ticker
=
time
.
Tick
(
10
*
1000
);
// 10 us
func
sleep
()
{
<-
ticker
;
<-
ticker
;
sys
.
Gosched
();
sys
.
Gosched
();
sys
.
Gosched
();
}
func
main
()
{
...
...
@@ -52,6 +67,8 @@ func main() {
var
s
string
;
var
ok
bool
;
var
sync
=
make
(
chan
bool
);
for
buffer
:=
0
;
buffer
<
2
;
buffer
++
{
c32
:=
make
(
chan
int32
,
buffer
);
c64
:=
make
(
chan
int64
,
buffer
);
...
...
@@ -70,45 +87,57 @@ func main() {
s
,
ok
=
<-
cs
;
if
ok
{
panic
(
"blocked ssender"
)
}
go
i32receiver
(
c32
);
pause
();
go
i32receiver
(
c32
,
sync
);
sleep
();
ok
=
c32
<-
123
;
if
!
ok
{
panic
(
"i32receiver"
)
}
go
i32sender
(
c32
);
pause
();
if
!
ok
{
panic
(
"i32receiver buffer="
,
buffer
)
}
<-
sync
;
go
i32sender
(
c32
,
sync
);
if
buffer
>
0
{
<-
sync
}
else
{
sleep
()
}
i32
,
ok
=
<-
c32
;
if
!
ok
{
panic
(
"i32sender
"
)
}
if
!
ok
{
panic
(
"i32sender
buffer="
,
buffer
)
}
if
i32
!=
234
{
panic
(
"i32sender value"
)
}
if
buffer
==
0
{
<-
sync
}
go
i64receiver
(
c64
);
pause
();
go
i64receiver
(
c64
,
sync
);
sleep
();
ok
=
c64
<-
123456
;
if
!
ok
{
panic
(
"i64receiver"
)
}
go
i64sender
(
c64
);
pause
();
<-
sync
;
go
i64sender
(
c64
,
sync
);
if
buffer
>
0
{
<-
sync
}
else
{
sleep
()
}
i64
,
ok
=
<-
c64
;
if
!
ok
{
panic
(
"i64sender"
)
}
if
i64
!=
234567
{
panic
(
"i64sender value"
)
}
if
buffer
==
0
{
<-
sync
}
go
breceiver
(
cb
);
pause
();
go
breceiver
(
cb
,
sync
);
sleep
();
ok
=
cb
<-
true
;
if
!
ok
{
panic
(
"breceiver"
)
}
go
bsender
(
cb
);
pause
();
<-
sync
;
go
bsender
(
cb
,
sync
);
if
buffer
>
0
{
<-
sync
}
else
{
sleep
()
}
b
,
ok
=
<-
cb
;
if
!
ok
{
panic
(
"bsender"
)
}
if
!
b
{
panic
(
"bsender value"
)
}
if
buffer
==
0
{
<-
sync
}
go
sreceiver
(
cs
);
pause
();
go
sreceiver
(
cs
,
sync
);
sleep
();
ok
=
cs
<-
"hello"
;
if
!
ok
{
panic
(
"sreceiver"
)
}
go
ssender
(
cs
);
pause
();
<-
sync
;
go
ssender
(
cs
,
sync
);
if
buffer
>
0
{
<-
sync
}
else
{
sleep
()
}
s
,
ok
=
<-
cs
;
if
!
ok
{
panic
(
"ssender"
)
}
if
s
!=
"hello again"
{
panic
(
"ssender value"
)
}
if
buffer
==
0
{
<-
sync
}
}
print
(
"PASS
\n
"
)
}
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