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. Got deadlock when i run my multiThread FTP application

Got deadlock when i run my multiThread FTP application

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmin
7 Posts 4 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi, I wrote some multiThread application that upload some file to FTP server. When i run 10 threads all work fine - but when i run 50 thread i have deadlock. I attached my code - this is the Connection method that each thread calls My code ...

    bool FTPConnection::UploadInfo(CString MachineIpAddress, CString FileToDownload)
    {
    try
    {
    CMyInternetSession InternetSession;
    CFtpConnection* ftpConnection = InternetSession.GetFtpConnection(MachineIpAddress, "admin", "admin");

    	if( !ftpConnection->SetCurrentDirectory("/SomeFtpFoled"))
    	{
    		int E = GetLastError();
    		return false;
    	}
    
    	if(!ftpConnection->PutFile(FileToDownload, FileToDownload))
    	{
    		int E = GetLastError();
    		return false;
    	}
    
    	return true;
    }
    catch (CException\* e)
    {
    	return false;	
    }
    

    }

    P M S 3 Replies Last reply
    0
    • L Lost User

      Hi, I wrote some multiThread application that upload some file to FTP server. When i run 10 threads all work fine - but when i run 50 thread i have deadlock. I attached my code - this is the Connection method that each thread calls My code ...

      bool FTPConnection::UploadInfo(CString MachineIpAddress, CString FileToDownload)
      {
      try
      {
      CMyInternetSession InternetSession;
      CFtpConnection* ftpConnection = InternetSession.GetFtpConnection(MachineIpAddress, "admin", "admin");

      	if( !ftpConnection->SetCurrentDirectory("/SomeFtpFoled"))
      	{
      		int E = GetLastError();
      		return false;
      	}
      
      	if(!ftpConnection->PutFile(FileToDownload, FileToDownload))
      	{
      		int E = GetLastError();
      		return false;
      	}
      
      	return true;
      }
      catch (CException\* e)
      {
      	return false;	
      }
      

      }

      P Offline
      P Offline
      pl_kode
      wrote on last edited by
      #2

      Are you syncronizing threads. If there is a problem of Syncronization of threads then try using Mutex, critical section etc. try to syncronize the threads.

      L 1 Reply Last reply
      0
      • P pl_kode

        Are you syncronizing threads. If there is a problem of Syncronization of threads then try using Mutex, critical section etc. try to syncronize the threads.

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

        The thread are synchronize. I don't think that this is the synchronize problem because each thread is running ok. But - when i press on pause button - i see that some thread(s) are still waiting on the line "GetFtpConnection" and other thread(s) are still waiting on "PutFile". So i think that the synchronize of the thread is ok - and maybe i have some communication problem.

        1 Reply Last reply
        0
        • L Lost User

          Hi, I wrote some multiThread application that upload some file to FTP server. When i run 10 threads all work fine - but when i run 50 thread i have deadlock. I attached my code - this is the Connection method that each thread calls My code ...

          bool FTPConnection::UploadInfo(CString MachineIpAddress, CString FileToDownload)
          {
          try
          {
          CMyInternetSession InternetSession;
          CFtpConnection* ftpConnection = InternetSession.GetFtpConnection(MachineIpAddress, "admin", "admin");

          	if( !ftpConnection->SetCurrentDirectory("/SomeFtpFoled"))
          	{
          		int E = GetLastError();
          		return false;
          	}
          
          	if(!ftpConnection->PutFile(FileToDownload, FileToDownload))
          	{
          		int E = GetLastError();
          		return false;
          	}
          
          	return true;
          }
          catch (CException\* e)
          {
          	return false;	
          }
          

          }

          M Offline
          M Offline
          Malli_S
          wrote on last edited by
          #4

          I don't think that the scenario you're talking about is 'dead lock'. You are calling the synchronous calls like PutFile which returns only when the task gets completed or failed. Try out with opening the file using OpenFile and Write functions. You'll get closer control over the code and thread.

          -Malli...! :rose:****

          L 1 Reply Last reply
          0
          • M Malli_S

            I don't think that the scenario you're talking about is 'dead lock'. You are calling the synchronous calls like PutFile which returns only when the task gets completed or failed. Try out with opening the file using OpenFile and Write functions. You'll get closer control over the code and thread.

            -Malli...! :rose:****

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

            The file are very small ( 2-3 Kb ) so i don't see any problem with waiting until the file will be done.

            M 1 Reply Last reply
            0
            • L Lost User

              The file are very small ( 2-3 Kb ) so i don't see any problem with waiting until the file will be done.

              M Offline
              M Offline
              Malli_S
              wrote on last edited by
              #6

              Closing the FTP connection after the use may help to reduce the number of connection load.

              -Malli...! :rose:****

              1 Reply Last reply
              0
              • L Lost User

                Hi, I wrote some multiThread application that upload some file to FTP server. When i run 10 threads all work fine - but when i run 50 thread i have deadlock. I attached my code - this is the Connection method that each thread calls My code ...

                bool FTPConnection::UploadInfo(CString MachineIpAddress, CString FileToDownload)
                {
                try
                {
                CMyInternetSession InternetSession;
                CFtpConnection* ftpConnection = InternetSession.GetFtpConnection(MachineIpAddress, "admin", "admin");

                	if( !ftpConnection->SetCurrentDirectory("/SomeFtpFoled"))
                	{
                		int E = GetLastError();
                		return false;
                	}
                
                	if(!ftpConnection->PutFile(FileToDownload, FileToDownload))
                	{
                		int E = GetLastError();
                		return false;
                	}
                
                	return true;
                }
                catch (CException\* e)
                {
                	return false;	
                }
                

                }

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #7

                On a side note, MFC exceptions should be deleted when caught with catch (e->Delete()).

                Steve

                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