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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:06:32+00:00 2026-05-29T21:06:32+00:00

Is the following int BlkArray::GetNthBlockA(unsigned int n, const Block *&pfb, int &maxIndex) const {

  • 0

Is the following

int BlkArray::GetNthBlockA(unsigned int n, const Block *&pfb, int &maxIndex) const {
    if (n + 1 >= (unsigned int)formattingPivots.GetCount()) return -1;
    pfb = formattingPivots.GetNthBlckB(n);
    maxIndex = formattingPivots.GetNthInt(n + 1) - 1;
    return formattingPivots.GetNthInt(n);
}

thread safe considering:

  1. formattingPivots.GetNthBlckB(n), formattingPivots.GetNthInt(n + 1), formattingPivots.GetNthInt(n) and formattingPivots.GetCount() are all const methods.
  2. I call GetNthBlock() from 2 threads, when thread1 calls and returns an usual Block I notice a side effect in thread2.
  3. const Block *&pfb is passed as follows from each thread’s worker method:

    int maxIndex;
    const Block *pfb = null;
    pStoredBlcks->GetNthBlockA(blockBreakIndex, pfb, maxIndex);
    

I’m concerned const might be causing an unintended effect in persisting between both workers’ bodies. I’m 98% the bugs I get are from the code above but, being peculiar to multithreading I can’t get much more sure.

I’m getting near my question limit for 24 hrs, on one more thing, if it might help. Is static_cast<> thread safe? (Silly? yeah but I wrote C for years) I ask because of:

const Block *GetNthblckB(int n) const {
    return static_cast<const Block*>(Blocks.GetAt(n));//Returns `Object`* without cast.
}

3am___
Thanks for the encouragement guys. I just surrounded that call with a CritSecMonitor and I still have the side effect. Short of reading the valgrind manual I better catch some zz’s.

  • 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-29T21:06:34+00:00Added an answer on May 29, 2026 at 9:06 pm

    In answer to my question, I thought someone else had already said this:

    Don’t assume any library function is thread safe unless it says it is.

    My 98% guess was wrong and the thread unsafe method lay elsewhere in a library instance method using completely seperate objects but being called from two threads. There must have been a static variable in there somewhere as the call stacks where it would crash (very rarely) looked to be deep inside library code.

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

Sidebar

Related Questions

Consider the following : int increment1 (const int & x) { return x+1; }
Consider the following: int ival = 1.01; int &rval = 1.01; // error: non-const
HI, I have a C++ function like the following: int ShowJob(const JobData& data); How
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr
Consider the following code: int main() { int *p; ++((int){5}); //compile without err/warning &((int){5});
I have the following code int main() { int a=6; void *p; p=&a; p++;
What is the Method Signature in the following int DoSomething(int a, int b); Return
I am trying the following C code: int main() { printf(text1\n); fork(); printf(text2\n); return
Suppose I have the following: int main() { SomeClass(); return 0; } Without optimization,
In C++ we have the following: int* p1; // pointer to int const int*

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.