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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:52:14+00:00 2026-06-07T13:52:14+00:00

In one C++ source file that I’m wrapping in a python function, someone has

  • 0

In one C++ source file that I’m wrapping in a python function, someone has included the following:

namespace some_namespace 
{ 
  static double some_double; 
}

float function_that_uses_some_double(float input) { 
  // implementation
  return result; 
}

The static global some_double is only ever used inside the function, so if I wrap this in a CPython function and call it in single-threaded code, the variable will only ever be used by one function at a time. It’s ugly, but no problem there. My question is what happens if I use:

  1. the threading module, or
  2. the multiprocessing module.

When I have multiple processes and / or threads using this module, will they interfere with each other?

  • 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-07T13:52:18+00:00Added an answer on June 7, 2026 at 1:52 pm

    If you use the threading module, then all functions will simply share that global variable. Threads in python are switched between bytecode boundaries, so locking is a non-issue.

    If you use the multiprocessing module, things are different and it depends a bit on your usage of multiprocessing. Python starts with a single process so, there is only one copy of the global variable. The value of that variable when you start using multiprocessing (i.e. forking new python processes from the main process) will be copied into the subprocesses (tasks), but those processes will each have their own copy of the global variable.

    If you get tricky and set up a shared memory segment (mmap with MAP_SHARED) and the variable is a pointer, then the location pointed to will be shared and you’ll need to use locking.

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

Sidebar

Related Questions

We have a source XML file that has an address node, and each node
each source file has a function: unsigned char test(){ //return true if tests succceed
I compiled a static library in xcode, it contained just one .c source file:
When I edit one source file, does running make recompile that file plus all
I've got an ActionScript 3 source file (.as) that has hundreds of untyped variables.
I have a c source file in which one of the method is defined
Please any one give me the suggestion for this. I'm having the Xerces-J-source.zip file
I've seen at least one reliable source (a C++ class I took) recommend that
I'm trying to put together a really simple module with one .py source file
I have a CPP source file that uses #if / #endif to compile out

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.