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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:02:23+00:00 2026-06-08T16:02:23+00:00

I am using such code in multithreading: Old example: class All { object lockAll

  • 0

I am using such code in multithreading:

Old example:

  class All
     {
        object lockAll = new object();
        public All ()
        {
           lock(lockAll)
           {
               double res= Magnitude(1d, 0.1d , 0.2d);
           }
        }
        private double Magnitude(double X, double Y, double Z)
        {
           return Math.Sqrt(X * X + Y * Y + Z * Z);
        }
     }

But i see that sometimes res is 1.3 * 10 ^-314. Why??? All is locked.:
Part of real code:

class PointSensors : IDisposable
    {
object lockAcs = new object(); //Can it be non static? I think yes
object lockMag = new object();
// When i got info from sensors. Multitheading method called many times every time in new thread
 public void OnSensorChanged(SensorEvent ev)
        {
            Sensor curS = ev.Sensor;
            long timeStamp = ev.Timestamp;
              // Vector from sensors
             Vector3 vector = new Vector3(ev.Values[0], ev.Values[1], ev.Values[2]);
                if (curS.Type == SensorType.Accelerometer)
                {
                    lock (lockAcs)
                    {
                       double TotalAcseleration = vector.Magnitude - 9.8d;
                       ...
                    }
                }

                if (curS.Type == SensorType.MagneticField))
                {
                    lock (lockMag)
                    {
                       double TotalMagVect = vector.Magnitude ;
                       ...
                    }
                }


        }
}

And sometimes Math functions give crazy results.

  • 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-08T16:02:25+00:00Added an answer on June 8, 2026 at 4:02 pm

    Your lock doesn’t make sense since res is not a shared variable. Its scope only exists within the lock so no other thread will have access to it anyway.

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

Sidebar

Related Questions

For example I'm using such a code: <?php require_once(D:\server/www/cls/PHPExcel.php); require_once(D:\server/www/cls/PHPExcel/IOFactory.php); $objPHPExcel = new PHPExcel();
I am using such code to present a new view, I don't it's good
I'm currently using such blocks of code in my project public ActionStatus GetStuff(out output)
I'm trying to compile such code: #include <iostream> using namespace std; class CPosition {
There is such code: #include <iostream> #include <vector> template <class T> class A{ public:
I'm using such code which works great on IE and Firefox: .tytulmalykom { color:#666666;
Given such a code segment: #include <iostream> #include <iterator> #include <fstream> #include <string> using
I would select multiple DOM elements using a typical code such as this: $('#ele1,
After updating to Parsec 3.1 from 2.x, code using many1, such as word =
I have such code using (Image image = System.Drawing.Image.FromStream(sourceStream)) { Guid objGuid = image.FrameDimensionsList[0];

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.