⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (1.15 KB)
Bug #14634
» queue2.rb
Reproduction script -
zetaben (Benoit Larroque)
, 03/26/2018 11:04 PM
# frozen_string_literal: true
require
'timeout'
# Object container
class
Obj
attr_accessor
:payload
def
initialize
(
value
)
@payload
=
value
end
end
def
random_hash
(
n
=
2
)
return
'str'
if
n
<=
0
ret
=
{}
10
.
times
do
|
i
|
ret
[
"key
#{
i
}
"
]
=
random_hash
(
n
-
1
)
end
Obj
.
new
(
ret
)
end
def
log
(
x
)
warn
(
"
#{
Process
.
pid
}
.
#{
Thread
.
current
.
object_id
}
:
#{
x
}
"
)
end
log
(
'Starting'
)
queue
=
Queue
.
new
Thread
.
new
do
log
(
"Consumer parent thread
#{
queue
.
object_id
}
"
)
event
=
nil
while
event
.
nil?
begin
event
=
Timeout
.
timeout
(
1
)
do
queue
.
pop
end
rescue
Timeout
::
Error
nil
end
end
log
(
"Consumer end parent thread
#{
queue
.
object_id
}
"
)
end
sleep
(
1
)
log
(
'Forking'
)
child_id
=
fork
if
child_id
.
nil?
Thread
.
new
do
log
(
"Consumer thread
#{
queue
.
object_id
}
"
)
event
=
nil
while
event
.
nil?
begin
event
=
Timeout
.
timeout
(
1
)
do
queue
.
pop
end
rescue
Timeout
::
Error
nil
end
end
log
(
"Consumer end thread
#{
queue
.
object_id
}
"
)
end
sleep
(
1
)
h
=
random_hash
(
4
)
queue
.
push
(
h
)
log
(
'finished child'
)
else
Process
.
wait
(
child_id
)
log
(
'finished parent'
)
end
« Previous
1
2
3
4
5
6
Next »
(3-3/6)
Loading...