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 8580339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:48:29+00:00 2026-06-11T20:48:29+00:00

I have worked on multithreading (in Qt) but i lack an in-depth knowledge. I

  • 0

I have worked on multithreading (in Qt) but i lack an in-depth knowledge. I think that the run-time never duplicates an execution code. A function will remain in precisely one memory location which all callers or object will use to invoke it. In multithreading i read that each thread gets its own stack, Instruction Pointers and so on. Let’s say we have a global function which translates to assembly algorithm like this:

//GlobalFunction()
instruction 1 : move value 4 into accumulator
instruction 2 : add 5 to content of accumulator
instruction 3 : subtract 1 from content of accumulator
//some more stuff and function returns

//thread 1
call GlobalFunction()

//thread 2
call GlobalFunction()

now maybe the instruction pointer of thread 1 points to instruction 3 while thread 2 gets the slice and executes instruction 1. After this thread 1 executes instruction 3. Won’t the accumulator data be corrupted for it? If so then why do functions using only non-static local variables do not require locking in multithreaded environment?

P.S: Also i suppose a single instruction is atomic not a group of instructions, so implementation might not get a chance of flushing the register data out into some storage location before executing instruction of another thread.

  • 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-06-11T20:48:30+00:00Added an answer on June 11, 2026 at 8:48 pm

    While there is only one set of registers on a CPU (for simplicity, I’m assuming a single core system), the system manages the register file such that each thread has it’s own separate register state – when the OS switches from one thread to another, the first thread’s registers are saved and the second thread’s saved registers are restored.

    For automatic/stack variables each thread gets it’s own stack, so unless the thread does something to explicitly share such a variable (by passing the address or a reference to another thread), those variables are not shared and so are thread-safe.

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

Sidebar

Related Questions

I have worked with Apache before, so I am aware that the default public
I have worked with pointers a lot, but still whenever I work with them,
I have worked many projects with no problems. But in current project, I tested
I have worked with Source Control softwares like VSS, TFS, ClearCase, SVN, etc. but
I have worked with MySQL more than MongoDB, but from what I've learned from
I have worked with SQL for several years now, primarily MySQL/PhpMyAdmin, but also Oracle/iSqlPlus
I have worked out how to detect touching on an object using glReadPixels but
I have worked with databases in my applications but I have only created private
I have worked with rails scaffold to generate forms and views automatically. But now
I have a extension that uses multithreading using worker thread as shown here .

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.