Solved

Thread Access problem

Posted on 2000-02-22
4
249 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 95
substring method in java 1 135
matchUp  challenge 6 76
My project did see openJDK that I installed. What could be the problem 7 161
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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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