Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Doubles change behavior in CreateThread process, why?

Doubles change behavior in CreateThread process, why?

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studioalgorithmshelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TragicComic
    wrote on last edited by
    #1

    Hello, I'm having a problem with my double precision variables right now, and I'm hoping someone out there will be able to give me a hint as to what's going on. The details are going to be a little sketchy simply because of the size and complexity of the application. I have a function that tests to see if the double precision code is behaving properly. This function looks something like this. void TestMath() { double kappa = -2.5316332141755993e-008; double cx; cx = (double)1.0 / (double)kappa; if (cx != -39500192.000000000){ BREAK("MATH IS WORKING"); } } When this function is called from the main body of my application, it never hits the break. However, if the function is called from a thread I have spawned using CreateThread(), the break does get hit. The value for cx should be -39500192.776766039, but it's being set to -39500192.000000000 And if I add the line double cx2 = 1.0 / -2.5316332141755993e-008; cx2 always equals -39500192.776766039 regardless of where I'm making the call. Using the IDE and checking the value for kappa indicates that it's value is correctly being stored. And again, if the function is called from a spawned thread, cx is evaluated to be -39500192.776766039 To create the thread, I'm simply calling handle = CreateThread( NULL, 0,(LPTHREAD_START_ROUTINE)threadProcess, parameter, 0, NULL); And the function declaration for the thread looks like this. DWORD WINAPI threadProcess(void *param) Does anyone have any suggestions as to what could be causing this behavior? Thanks, Adam

    T 1 Reply Last reply
    0
    • T TragicComic

      Hello, I'm having a problem with my double precision variables right now, and I'm hoping someone out there will be able to give me a hint as to what's going on. The details are going to be a little sketchy simply because of the size and complexity of the application. I have a function that tests to see if the double precision code is behaving properly. This function looks something like this. void TestMath() { double kappa = -2.5316332141755993e-008; double cx; cx = (double)1.0 / (double)kappa; if (cx != -39500192.000000000){ BREAK("MATH IS WORKING"); } } When this function is called from the main body of my application, it never hits the break. However, if the function is called from a thread I have spawned using CreateThread(), the break does get hit. The value for cx should be -39500192.776766039, but it's being set to -39500192.000000000 And if I add the line double cx2 = 1.0 / -2.5316332141755993e-008; cx2 always equals -39500192.776766039 regardless of where I'm making the call. Using the IDE and checking the value for kappa indicates that it's value is correctly being stored. And again, if the function is called from a spawned thread, cx is evaluated to be -39500192.776766039 To create the thread, I'm simply calling handle = CreateThread( NULL, 0,(LPTHREAD_START_ROUTINE)threadProcess, parameter, 0, NULL); And the function declaration for the thread looks like this. DWORD WINAPI threadProcess(void *param) Does anyone have any suggestions as to what could be causing this behavior? Thanks, Adam

      T Offline
      T Offline
      TragicComic
      wrote on last edited by
      #2

      Found it! :D So, one of the details that I left out was that I am using DirectX for GPGPU math processing as well as for displaying 3d objects. It turns out that if you create a D3DDevice without the behavior flag D3DCREATE_FPU_PRESERVE, the following happens: Without this flag, Direct3D defaults to setting the FPU to single-precision round-to-nearest mode. Using this flag with the FPU in double-precision mode will reduce Direct3D performance. Don't you just love how moments after you post about a problem, your thinking changes just enough to allow you to find the culprit? Thanks for forum, Adam

      D 1 Reply Last reply
      0
      • T TragicComic

        Found it! :D So, one of the details that I left out was that I am using DirectX for GPGPU math processing as well as for displaying 3d objects. It turns out that if you create a D3DDevice without the behavior flag D3DCREATE_FPU_PRESERVE, the following happens: Without this flag, Direct3D defaults to setting the FPU to single-precision round-to-nearest mode. Using this flag with the FPU in double-precision mode will reduce Direct3D performance. Don't you just love how moments after you post about a problem, your thinking changes just enough to allow you to find the culprit? Thanks for forum, Adam

        D Offline
        D Offline
        DQNOK
        wrote on last edited by
        #3

        Nice post. Maybe it'll save someone else the trouble. Thanks for sharing it. David

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups