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. ):

):

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 3 Posters 1 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.
  • J Offline
    J Offline
    JayBoyy
    wrote on last edited by
    #1

    :suss::suss:

    L B 4 Replies Last reply
    0
    • J JayBoyy

      :suss::suss:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Are you and Scholar247 the same person? If so please request removal of one profile. As to your questions:

      1. This site does not provide code to order. Google is the place for samples.
      2. The consequences of a race condition may vary from incorrect results, to a program not responding.
      3. There are many different situations when this may be appropriate, but it depends on the problem to be solved.
      4. Impossible to answer as any problem's ease of resolution depends on a lot of factors.
      1 Reply Last reply
      0
      • J JayBoyy

        :suss::suss:

        B Offline
        B Offline
        Babu_Abdulsalam
        wrote on last edited by
        #3

        int g_x = 0; DWORD WINAPI Add(void* p) //p unused parameter { g_x++; } void main() { HANDLE m_hArr[10]; int i = 0; for( ; i < 10; i++ ) { CreateThread( NULL,0,Add,NULL,0,&m_hArr[i]); } //Wait for all the 10 threads to complete its execution ::WaitForMultipleObjects(10,m_hArr,TRUE,INDEFENITE); //Now print the result.You expect 10 but it may not be... :) cout<<"g_x = "<

        1 Reply Last reply
        0
        • J JayBoyy

          :suss::suss:

          B Offline
          B Offline
          Babu_Abdulsalam
          wrote on last edited by
          #4

          Because the order of the execution. Suppose you have 4 floats a,b,c,d and you want to sum up them. In case of serial implementation, it will be like a + b + c + d But in case of parallel, it may execute like (a+b) + (c+d) So the result wont be same. This answers your 4th question.

          1 Reply Last reply
          0
          • J JayBoyy

            :suss::suss:

            B Offline
            B Offline
            Babu_Abdulsalam
            wrote on last edited by
            #5

            2. Consequence of race condition: Your resource will go to a corrupted state. Not getting the expected result etc.,

            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