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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. About Thread Synchronization

About Thread Synchronization

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminjson
5 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.
  • H Offline
    H Offline
    hanq_38910130
    wrote on last edited by
    #1

    Hi all, I'm having an application for Remote control, but there are some problems in its part of network connections.I have tried for weeks, still can't find out the reason for that. In our program, we don't use thread synchronization in function "TCPSock->Recv"(winsock api recv() is used in it), because this function is only used in single thread. Today, I tried to add thread synchronization to this function.As a result, these network connections problems are fixed(at least it seems to be). My question is, "Is thread synchronization needed when only using a function in single thread?" Regards, HQ

    R 1 Reply Last reply
    0
    • H hanq_38910130

      Hi all, I'm having an application for Remote control, but there are some problems in its part of network connections.I have tried for weeks, still can't find out the reason for that. In our program, we don't use thread synchronization in function "TCPSock->Recv"(winsock api recv() is used in it), because this function is only used in single thread. Today, I tried to add thread synchronization to this function.As a result, these network connections problems are fixed(at least it seems to be). My question is, "Is thread synchronization needed when only using a function in single thread?" Regards, HQ

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      hanq_38910130 wrote:

      "Is thread synchronization needed when only using a function in single thread?"

      It is actually the other way round. If you are using multiple threads, then you try to synchronize access to the code that must be protected from multiple simultaneous accesses. Or is that you are referring to an additional worker thread (other than the application's main thread) while saying a "Single thread"?

      It is a crappy thing, but it's life -^ Carlo Pallini

      H 1 Reply Last reply
      0
      • R Rajesh R Subramanian

        hanq_38910130 wrote:

        "Is thread synchronization needed when only using a function in single thread?"

        It is actually the other way round. If you are using multiple threads, then you try to synchronize access to the code that must be protected from multiple simultaneous accesses. Or is that you are referring to an additional worker thread (other than the application's main thread) while saying a "Single thread"?

        It is a crappy thing, but it's life -^ Carlo Pallini

        H Offline
        H Offline
        hanq_38910130
        wrote on last edited by
        #3

        Thanks for your replay:) Yes, I mean "an additional worker thread" when I say "a single thread". Our program mainly has two parts, server and client. server accepts connections from client, when a connection is accepted, it creates a "worker thread" to communicate with the client. Only in this thread, "TCPSock->Recv()" will be called, so originally we don't use a "Thread Synchronization". But today, I Added "Thread Synchronization", and the bugs seem to be fixed, so I want to know "Is Thread Synchronization needed in single thread in some conditions?" Thanks very much :)

        R 1 Reply Last reply
        0
        • H hanq_38910130

          Thanks for your replay:) Yes, I mean "an additional worker thread" when I say "a single thread". Our program mainly has two parts, server and client. server accepts connections from client, when a connection is accepted, it creates a "worker thread" to communicate with the client. Only in this thread, "TCPSock->Recv()" will be called, so originally we don't use a "Thread Synchronization". But today, I Added "Thread Synchronization", and the bugs seem to be fixed, so I want to know "Is Thread Synchronization needed in single thread in some conditions?" Thanks very much :)

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          hanq_38910130 wrote:

          But today, I Added "Thread Synchronization", and the bugs seem to be fixed

          Glad about that.

          hanq_38910130 wrote:

          "Is Thread Synchronization needed in single thread in some conditions?"

          But, I still am not able to understand this. If it is just one thread accessing the code that must be 'protected', then it does not matter how many other threads are running simultaneously. But if more than one thread can possibly access the code that must be protected, then you need synchronization. I hope I am clear. There is a whole lot of information on this topic here[^] if you would like to read up.

          It is a crappy thing, but it's life -^ Carlo Pallini

          H 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            hanq_38910130 wrote:

            But today, I Added "Thread Synchronization", and the bugs seem to be fixed

            Glad about that.

            hanq_38910130 wrote:

            "Is Thread Synchronization needed in single thread in some conditions?"

            But, I still am not able to understand this. If it is just one thread accessing the code that must be 'protected', then it does not matter how many other threads are running simultaneously. But if more than one thread can possibly access the code that must be protected, then you need synchronization. I hope I am clear. There is a whole lot of information on this topic here[^] if you would like to read up.

            It is a crappy thing, but it's life -^ Carlo Pallini

            H Offline
            H Offline
            hanq_38910130
            wrote on last edited by
            #5

            ;) Thanks for your help. I will look into the linking which you provided to see if there can be any useful information. Add maybe the reason that causes all these problems exist in some other code, anyway I will check this. ;P

            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