Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared tds.hash gives sigsegv #51

Open
octavian-ganea opened this issue Feb 18, 2016 · 1 comment
Open

Shared tds.hash gives sigsegv #51

octavian-ganea opened this issue Feb 18, 2016 · 1 comment

Comments

@octavian-ganea
Copy link

I am trying to figure out the proper way to update a shared tds.hash by multiple threads concurrently. The following code inspired after test-threads-shared.lua gives 'Segmentation fault (double free or corruption)' every time I run it:

function f()
  local threads = require 'threads'
  threads.Threads.serialization('threads.sharedserialize')
  local njob = 10
  local tds = require 'tds'
  local dict = tds.Hash()
  collectgarbage()
  collectgarbage()

  local pool = threads.Threads(
    10,
    function(threadIdx)
    end
  )

  for k=1,njob do
    pool:addjob(
      function()
        for i = 1,100000 do
          dict[i * 11 + k] = math.random()
        end
        collectgarbage()
        collectgarbage()
        return __threadid
      end,
      function(id)
      end
    )
  end

  for k=1,njob do
    pool:addjob(
      function()
        collectgarbage()
        collectgarbage()
      end
    )
  end
  pool:synchronize()
  pool:terminate()
  return dict
end

a = f()
print(a[1])

Any ideas if the problem is on my side ? Thanks.

@colesbury
Copy link
Contributor

I don't think tds.hash is thread-safe for multiple writers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants