Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:04:28+00:00 2026-05-26T23:04:28+00:00

I am working on a performance critical system that has a lot of logging.

  • 0

I am working on a performance critical system that has a lot of logging. I am planning to do my major computation in a thread that sticks to one core, and logs in another thread that sticks to another core. How do I achieve that in pthread_setaffinity_np() ?

I imagine that my code would look like

void log_something(const string& st) {
  pthread_setaffinity_np(pthread_self(),sizeof(cpuset),&cpuset);
  //LOG string st; 
}

int main() {
   while (true) {
      // do some computation
      log_something(something)
   }
}

My question is, when I call pthread_setaffinity_np() in log_something(), would it do the logging in the cpu I specified, and while doing the logging, return to the while loop of main() and continue the computation?

Or it will switch the entire program to that cpu set, and will only return to main method after logging?

Thanks!

[EDITED] I use logging as an example but my practical problem is more complicated than that. For example, I might have to update a dynamic parameter every minute, and while I am updating the parameter, I still want to continue my computation in the main() method based on the old parameter (i.e. I just can’t stop my main computation for parameter updating). Therefore the process of updating the parameters might have to be migrated to another thread that sticks to another core. So I am looking for a generic solution of separating the computation, not just an efficient logger.

Sorry for the confusion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:04:29+00:00Added an answer on May 26, 2026 at 11:04 pm

    You’ll need two separate threads, and each will call pthread_setaffinity_np when it starts up.

    If log_something is called from the computation thread, and logging is intended to be done on the logging thread, then it will have to place the message on a queue for the logging thread to deal with, rather than doing the logging itself. The logging thread will poll that queue, and log any messages it finds there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a system that requires high file I/O performance (with C#). Basically,
I'm doing some performance-critical Python work and want to create a function that removes
I am working on one project for performance enhancement. I had one doubt, while
I am working on getting the performance parameters of a tcp connection and one
I was working with ANTS Performance Profiler for few days and one of the
I'm currently working on some performance critical code, and I have a particular situation
While working with MySQL and some really performance greedy queries I noticed, that if
I'm currently working on a performance critical application which incorporates legacy c code (a
I am working on high performance web application that uses jetty and jersey for
I'm working on some Oracle performance issues with our web app. One thing I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.