You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a table H_next and I do some calculation (call add()) and store value in H_next, which is shared across all the threads.
local function add(a,b)
return (a+b)
end
function indexer:cal()
local H_next={}
local temp_H_next={}
local count = 1
for i = 1,100 do
local val =10
self.pool:addjob(function()
H_next[i] = add(i,val+1)
--print (H_next[i])
return H_next
end
,
function(val)
for i=1,#val do
temp_H_next[count] = val[i]
count = count + 1
end
--temp_H_next[count] = val
--[[H_next[count] = val
count = count + 1--]]
end)
end
self.pool:synchronize()
self.pool:terminate()
for i,v in pairs(temp_H_next) do
print (i,v)
end
end
This just prints 2 values
I am only able to get all the values when I modify the function as follows
local H_next={}
local temp_H_next={}
local count = 1
for i = 1,100 do
local val =10
self.pool:addjob(function()
H_next[i] = add(i,val+1)
--print (H_next[i])
return H_next[i] -- When I return one by one
end
,
function(val)
--[[for i=1,#val do
temp_H_next[count] = val[i]
count = count + 1
end--]]
temp_H_next[count] = val
count = count + 1
end)
end
The problem with 2nd approach is that it takes a lot of time to communicate between child and main thread, I want to fill the H_next table for that particular thread then transfer those values or copy those values in main thread in temp_H_next using endcallback.
Is there a better way to do this, where I don't have to send one by one value at a time?
The text was updated successfully, but these errors were encountered:
I have a table H_next and I do some calculation (call add()) and store value in H_next, which is shared across all the threads.
This just prints 2 values
I am only able to get all the values when I modify the function as follows
The problem with 2nd approach is that it takes a lot of time to communicate between child and main thread, I want to fill the H_next table for that particular thread then transfer those values or copy those values in main thread in temp_H_next using endcallback.
Is there a better way to do this, where I don't have to send one by one value at a time?
The text was updated successfully, but these errors were encountered: