Skip to content

Refactor thread management methods#344

Merged
ko1 merged 4 commits intoruby:masterfrom
st0012:refactor-thread-management
Oct 31, 2021
Merged

Refactor thread management methods#344
ko1 merged 4 commits intoruby:masterfrom
st0012:refactor-thread-management

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Oct 26, 2021

I was catching up all the recent changes and I think some small changes can make the code easier to understand.

}
@tp_load_script.enable

@thread_stopper = begin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason to lazy-evaluate this value and assign it in the constructor seems more intuitive to understand? (and can save some additional checks)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this change. lazyness is not important (so you can call thread_stopper here) but complex logic should be located near lines.

setup_threads
thc = thread_client Thread.current
thc.is_management
thc = get_thread_client Thread.current
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thread_client feels like a variable instead of a method call. and I think adding the get_ prefix matches other method names like ask_thread_client.

end

def thread_switch n
def switch_thread n
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of other methods are named in the Verb-Noun fashion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it intends: thread.switch
but okay to change.

end

private def thread_client_create th
private def create_thread_client th
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of other methods are named in the Verb-Noun fashion.

@th_clients[th] = ThreadClient.new((@tc_id += 1), @q_evt, Queue.new, th)
end

private def ask_thread_client th = Thread.current
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this default value is never used.

@st0012 st0012 force-pushed the refactor-thread-management branch from 9a21105 to 97134a8 Compare October 28, 2021 15:59

def deactivate
thread_client.deactivate
@thread_stopper.disable if @thread_stopper
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ko1 I still think initializing @thread_stopper at the beginning and get rid of this check is important, so I changed my approach a bit instead of revert it. can you check it again?

@ko1 ko1 merged commit 5e12b05 into ruby:master Oct 31, 2021
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

Successfully merging this pull request may close these issues.

2 participants