Solved

Thread Access problem

Posted on 2000-02-22
4
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 8

Expert Comment

by:VinExpert
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 300 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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