Skip to content

Race conditions? #617

@MegaFPyKT

Description

@MegaFPyKT

Hello. Sorry for my english, but tell me please. This is normal behavior?

def test(i) 
sleep(1)
return i
end

def test1()
g=[]
pool = Concurrent::FixedThreadPool.new(20)
 for i in 1..5 do
      pool.post do
      g[i]=test(i)   
      end
 end
sleep 5
p g
end
test1()

Result:
[nil, nil, nil, 3, nil, 5]
or
[nil, nil, nil, nil, 4, 5]
or
[nil, nil, 2, 3, nil, nil]

If I add a "sleep()"

 def test(i)
sleep(1)
return i
end

def test1()
g=[]
pool = Concurrent::FixedThreadPool.new(20)
 for i in 1..5 do
     sleep(0.1)
      pool.post do
      g[i]=test(i)   
      end
 end
sleep 5
p g
end
test1()

Result:
[nil, nil, 2, 3, 4, 5]


  • Operating system: linux
  • concurrent-ruby version: 1.0.3
  • concurrent-ruby-ext installed: yes / no
  • concurrent-ruby-edge used: yes / no

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAn user question, does not change the library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions