Skip to content

Commit

Permalink
Fixes [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
ligurio committed Oct 18, 2024
1 parent 2202b83 commit 8bc2285
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 14 additions & 12 deletions molly/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ local function process_operation(client, history, op, thread_id_str, thread_id,
op = op()
end

assert(type(op) == 'table', 'Type of operation is not a Lua table.')
local err_msg = ('"operation" is not a Lua table: %s'):format(tostring(op))
assert(type(op) == 'table', err_msg)

op.type = 'invoke'
op.process = thread_id
Expand All @@ -31,10 +32,11 @@ local function process_operation(client, history, op, thread_id_str, thread_id,
history:add(op)
local ok, res = pcall(client.invoke, client, op, client_data)
if not ok then
log.warn('Process %d crashed (%s)', thread_id, res)
res.type = 'fail'
return
log.info('Process %d crashed (%s)', thread_id, res)
-- res.type = 'fail'
-- return
end
res.type = 'ok'
if res.type == nil then
error('Operation type is empty.')
end
Expand Down Expand Up @@ -74,21 +76,21 @@ local function run_client(thread_id, opts)
-- TODO: Add barrier here.

local gen, param, state = ops_generator:unwrap()
shared_gen_state = state
local op
local thread_id_str = '[' .. tostring(thread_id) .. ']'
while true do
state, op = gen(param, shared_gen_state)
if state == nil then
break
end
shared_gen_state = state
shared_gen_state = state
state, op = gen(param, shared_gen_state)
while op ~= nil do
ok, err = pcall(process_operation, client, history, op, thread_id_str, thread_id, client_data)
if ok == false then
error('Failed to process an operation', err)
log.info('ERROR: %s', err)
return false, err
end

require('fiber').yield()

shared_gen_state = state
state, op = gen(param, shared_gen_state)
end

-- TODO: Add barrier here.
Expand Down
4 changes: 2 additions & 2 deletions molly/threadpool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ local function start(self, ...)
local func, opts = ...
for thread_id = 1, self.thread_num do
log.debug('Spawn a new thread %d', thread_id)
local ok = self.pool[thread_id]:create(func, opts)
local ok, err = self.pool[thread_id]:create(func, opts)
if not ok then
error('Failed to start thread')
error('Failed to start thread:' .. err)
end
if THREAD_TYPE == 'fiber' then
self.pool[thread_id]:yield()
Expand Down

0 comments on commit 8bc2285

Please sign in to comment.