Solved

Multithread barrier

Posted on 2003-10-29
10
497 Views
Last Modified: 2013-11-20
I keep running into this problem in my efforts to multithread successfully. As many of you know, there is a problem passing CObject derived objects from one thread to another. Right now here is my problem. I have a DCCConnection (a file download object). This object handles all of the connecting to a server and recieving of a file in a worker thread, the thread updates members of the DCCConnection object that contain information about download speed, progress, and percent complete. Now..in this DCCConnection object I have a CProgressDlg object (as a member) that I want to be displayed during downloads. I want to place a timer in this object that updates the dialog by checking the DCCConnection object members for the latest info and then updating the dialog display. Here is the problem. This all seemed to be good in theory...but what I need my dialog to have is a pointer to the DCCConnection object. I can't seem to include the DCCConncetion.h file in my progress header. It fails terribly at compile time. Now it might be helpful to know that DCCConnection.h already includes Progress.h and that I want Progress.h to include DCCConnection.h. The only way I can let the ProgressDlg object access the DCCConnection members is to give it a pointer to the DCCConnection object. What on earth is the problem here??
0
Comment
Question by:SGyves
  • 7
  • 3
10 Comments
 

Author Comment

by:SGyves
ID: 9644824
Oh yeah..the reason I listed this under multithreading title is because...ordinarily...you could call functions to set members of the CProgressDlg...and then just have the timer look at those...however...this would leave the CProgress dialog being accessed by the main and the worker thread....which is a no-no.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9644958
What errors do you get? Do you have "multiple inclusion guards", e.g.

//DCCConnection.h:
#ifndef __DCCConnection_h
#define __DCCConnection_h

// rest of the header file goes here...

#endif
0
 

Author Comment

by:SGyves
ID: 9645577
It is telling me everything from missing a ; (which of course I am not because if I remove the inclusion...I do not get the error. It also tell me that CProgressDlg is missing its storage-class or type identifiers.

I tried doing the protection described above...here I will paste the .h files.

#pragma once
#include "afxcmn.h"
#include "DCCConnection.h"

#ifndef ProgressDlg_h
#define ProgressDlg_h

// CProgressDlg dialog

class CProgressDlg : public CDialog
{
      DECLARE_DYNAMIC(CProgressDlg)

public:
      CProgressDlg(CWnd* pParent = NULL);   // standard constructor
      virtual ~CProgressDlg();

// Dialog Data
      enum { IDD = IDD_DIALOG_XFER_PROG };

protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

      DECLARE_MESSAGE_MAP()
public:
      CProgressCtrl m_prgctlPercentComp;
      void SetFileSize(long int fs);
private:
      long int m_lFileSize;
      CString m_sFileName;
      CString m_sPercComp;
      CDCCConnection* m_pdcc;
};

#endif




#pragma once

#include "resource.h"
#include "ProgressDlg.h"

#ifndef DCCConnection_h
#define DCCConnection_h

class CDCCConnection
{
public:
      CDCCConnection(CString ip, CString p, CString fs, CString fn);
      virtual ~CDCCConnection(void);

private:
      u_long m_lIP;
      u_short m_nPort;
      CString m_sFileName;
      long m_lFileSize;
      CProgressDlg* pDlg;
      

public:
      CString GetDCCPort(void);
      CString GetDCCIP(void);
      CString GetDCCFileSize(void);
      CString GetDCCFileName(void);
      static UINT FileTransProc(LPVOID pParam);
      UINT RecieveFileToDisk(void);
      void DoRecieveFile(void);
      
};

#endif


Maybe that will help....
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 86

Expert Comment

by:jkr
ID: 9645628
And where in the above should the ';' be missing?
0
 

Author Comment

by:SGyves
ID: 9645784
There is no ';' missing....it is just that in CProgressDlg.h....it claims to not know what a:

CDCCConnection* m_pdcc;


is. It claims that CDCCConnection an error:

c:\Documents and Settings\mod_test\My Documents\Visual Studio Projects\GoIRC\DCCConnection.h(20): error C2501: 'CDCCConnection::CProgressDlg' : missing storage-class or type specifiers

Even though I am telling it what it is by putting the DCCConnection.h in the file.
0
 

Author Comment

by:SGyves
ID: 9645792
It claims to be missing a ';' before CDCCConnection* m_pdcc;
0
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 9645821
>>It claims that CDCCConnection an error

And it is right :o)

This is one of the 'vicious circle' include problems. But, there is a simple solution - a foward declaration:

#ifndef ProgressDlg_h
#define ProgressDlg_h

#ifndef DCCConnection_h // haven't seen this header yet
class CDCCConnection;
#endif

// CProgressDlg dialog
0
 

Author Comment

by:SGyves
ID: 9645853
Yes...I thought there was some problem with circular definitions...I just didn't know how to get rid of it. Thank you   :)

0
 

Author Comment

by:SGyves
ID: 9646048
Now it is saying use of undefined type in my .cpp when I try to reference my CDCCConnection object.

What is up with that??
0
 

Author Comment

by:SGyves
ID: 9646151
Just included the .h for DCCConnection in there...it is okay now

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question