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

Assign names to threads #716

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

dmklepp
Copy link

@dmklepp dmklepp commented Apr 26, 2024

Added a thread name char * argument to Thread constructor and applied changes to inherited classes. Added assign_name_() method for different architectures. Also added print_name() method for debugging to keep name_ member private.

Issue link: #618

@github-actions github-actions bot added work in progress Pull request is still in progress and changing needs rebase Pull request has conflicts and should be rebased labels Apr 27, 2024
Copy link

🤖 The latest upstream change made this pull request unmergeable. Please resolve the merge conflicts.

@dmklepp dmklepp marked this pull request as ready for review April 27, 2024 01:57
@github-actions github-actions bot added ready for review Pull request can be reviewed and removed work in progress Pull request is still in progress and changing labels Apr 27, 2024
@gavv
Copy link
Member

gavv commented May 6, 2024

Hi, thanks for the patch! Could you please rebase on fresh develop? There are conflicts.

@gavv gavv added the contribution A pull-request by someone else except maintainers label May 8, 2024
@gavv gavv changed the title issue_618 ready for review Assign names to threads May 8, 2024
Copy link
Member

@gavv gavv left a comment

Choose a reason for hiding this comment

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

Here are a few comments on the code itself.

Comment on lines +64 to +69
// Thread::Thread()
// : started_(0)
// , joinable_(0)
// , name_(nullptr)
// {
// }
Copy link
Member

Choose a reason for hiding this comment

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

Please remove commented code.

Comment on lines +91 to +94
#else
pthread_setname_np(pthread_self(), name_);
return true;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Since pthread_setname_np() is not portable, we should guard this too, I think in this case it can be if defined(__GLIBC__) (because not all linux libc-s have that function).

Comment on lines +117 to +121
if (!assign_thread_name_()) {
roc_log(LogError, "thread: unable to assign thread name");
return false;
}

Copy link
Member

Choose a reason for hiding this comment

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

We should call it from thread_runner_(), not in start(), because __APPLE__ version work only for current thread.

Comment on lines +95 to +96
}
return false;
Copy link
Member

Choose a reason for hiding this comment

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

Since this is an optional feature for debugging, if there is no appropriate ifdef (e.g. when compiling for some less popular unix variant), it should not be an error. We should just do nothing.

Comment on lines +153 to +156
// for my own debugging purposes
void Thread::print_name() {
printf("Thread name: %s\n", name_);
}
Copy link
Member

Choose a reason for hiding this comment

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

Please remove debug printfs when submitting patches.

@@ -15,7 +15,8 @@ namespace roc {
namespace ctl {

ControlTaskQueue::ControlTaskQueue()
: started_(false)
: Thread("roc_ctrl_task_queue")
Copy link
Member

Choose a reason for hiding this comment

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

Since this thread actually serves requests to ctl::ControlLoop, let's call it roc_control_loop.

@@ -36,7 +36,8 @@ class Receiver : public core::Thread {
size_t num_chans,
size_t frame_size,
unsigned flags)
: recv_(NULL)
: Thread("roc_receiver")
Copy link
Member

Choose a reason for hiding this comment

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

Here in below: to avoid inventing names for each test, since these names in tests are not important anyway, maybe let's just use same name like "roc_test", "test_thread", or something like this?

I don't want to make name optional, so we have compiler error if non-test code forgets to assign a name. But on the other hand maintaining those names in tests feels unnecessary.

// {
// }

Thread::Thread(const char* name_)
Copy link
Member

Choose a reason for hiding this comment

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

name_ => name

(trailing underscore is for private members)

Comment on lines +73 to +75
, joinable_(0)
, name_(name_) {
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a panic triggered if name is NULL.

@gavv gavv added needs revision Pull request should be revised by its author and removed ready for review Pull request can be reviewed labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution A pull-request by someone else except maintainers needs rebase Pull request has conflicts and should be rebased needs revision Pull request should be revised by its author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants