Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Thread Access problem

Posted on 2000-02-22
4
Medium Priority
?
270 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

722 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