Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Thread Access problem

Posted on 2000-02-22
4
Medium Priority
?
279 Views
Last Modified: 2013-11-20
I have a multhread program that simulate phone operation. In this program I have a class defined like this.

class Line
{
enum LineStates{BUSY,AVAILABLE,UNAVAILABLE};
public:
 // constructor destructor
      Line ();
      ~Line ();
      friend UINT ctrltask (void *);
 // attributes
private:
      // line specific attributes
      LineStates LineState;
      
      // call specific attributes
      int            iDialType;
      char      cDate[20];
      char      cStartTime[20];
      char      cEndTime[20];

 // member functions
public:
      char cDialDigit[15];

      void SetDialDigit (char *cBuffer);
      void SetStartTime (char *cBuffer);
      void SetEndTime (char *cBuffer);
      void SetDate (char *cBuffer);
      void GetStartTime (char *cBuffer);
      void GetEndTime (char *cBuffer);
      void GetDate (char *cBuffer);
      int  GetLineStatus ();
      void GetDigitDialed (char *cBuffer);
      void Onhook ();
      int GetLine ();
};

When I call the SetDialDigit member function from the main thread I have no problem. But When I launch a thread using AfxBeginThread and I call that same member function, and the function tries to access one of it's member variables,private or public I get an access violation error. Can anyine help?.

0
Comment
Question by:BlackRussian
4 Comments
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2548992
Hi,

Pls can U post the code for the thread?

VinExpert
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2549038

 BlackRussian> I get an access violation error. Can anyine help?.

Before anyone can get started helping you, you owe us lots more information.

1) Provide the exact text of the access violation message.
2) Provide a symbolic stack trace to the exception.
3) Show the involved source code.

..B ekiM
0
 

Expert Comment

by:kakamna
ID: 2549226
When U want to run another worket thread the function controlling thread should be Satic and Static member function can not access the Class member variables.
So either use to global variables or pass the variables to a global thread controlling function as LPVOID Pointer.
0
 

Accepted Solution

by:
Stanislav022200 earned 1200 total points
ID: 2549630
Trying to answer your question (not sure, but trying):
when you call some function as thread, it (the function) should have some
specific profile. I mean ti must return UINT, it must get as a parameter
LPVOID and so on. Try this solution. Udachi!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

916 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