Solved

Thread Access problem

Posted on 2000-02-22
4
208 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:VinExpert
Comment Utility
Hi,

Pls can U post the code for the thread?

VinExpert
0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility

 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now