Hi,
i still have some problems of basic understanding of the threading currently i am showing the pseudo code of what i have written
/* main.h */
{
Q_Object
public:
readinputstatuschangeLedColourtoGreen();
maketheflagTrue();
}
class mythread:public Thread
{
Q_Object
public:
mythread();
protected:
void run();
public:
int my_flag;
public slots:
void maketheflagTrue();
}
/* main.cpp*/
int main(int argc, char *argv[])
{
Window window;
mythread threadA;
threadA.start();
window.show();
return app.exec();
}
/* file1.cpp */
test test1; // created object of test
window::Window
{
// created a gui with all the switches and Leds (switches are normal push button switches and leds are
// normal circles where you can fill with either green or red colour depending on the input data from
// pci based input card.
QObject::connection(button1,
SIGNAL(clicked
()),
&test1,
SLOT(maketheflagTrue
()));
}
/* main.cpp*/
mythread::mythread()
{
my_flag = FALSE;
}
mythread::run()
{
while(!myflag)
{
}
readinputstatuschangeLedColourtoGreen();
my_flag = FALSE;
}
/*file3.c*/
extern test test1;
void test:: readinputstatuschangeLedColourtoGreen()
{
// based on the input data i would make the leds green or red if input is 1 or 0 respectively.
}
void test::maketheflagTrue()
{
test1.my_flag = TRUE;
}
/* main.h */
class test:public QObject
{
Q_Object
public:
readinputstatuschangeLedColourtoGreen();
maketheflagTrue();
}
class mythread:public Thread
{
Q_Object
public:
mythread();
protected:
void run();
public:
int my_flag;
public slots:
void maketheflagTrue();
}
/* main.cpp*/
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
Window window;
mythread threadA;
threadA.start();
window.show();
return app.exec();
}
/* file1.cpp */
test test1; // created object of test
window::Window
{
// created a gui with all the switches and Leds (switches are normal push button switches and leds are
// normal circles where you can fill with either green or red colour depending on the input data from
// pci based input card.
QPushButton *button1 = new QPushButton("BUTTON1");
QObject::connection(button1, SIGNAL(clicked()), &test1, SLOT(maketheflagTrue()));
}
/* main.cpp*/
mythread::mythread()
{
my_flag = FALSE;
}
mythread::run()
{
while(!myflag)
{
}
readinputstatuschangeLedColourtoGreen();
my_flag = FALSE;
}
/*file3.c*/
extern test test1;
void test:: readinputstatuschangeLedColourtoGreen()
{
// based on the input data i would make the leds green or red if input is 1 or 0 respectively.
}
void test::maketheflagTrue()
{
test1.my_flag = TRUE;
}
To copy to clipboard, switch view to plain text mode
i will very quickly and briefly explain the code
1. i have to actually get the data from the pci card which currently i am trying to simulate with button1 and the flag i am using my_flag.
2. my main purpose is read some input data and color the led which i am trying to do it in thread.
Questions:
1. i have started the thread by making the my_flag variable FALSE. so once the thread is started will the program hang in the thread itself as per the following code
while(!myflag)
{
}
while(!myflag)
{
}
To copy to clipboard, switch view to plain text mode
or it will be in the main thread and constantly looking for the my_flag variable change using scheduling mechanism. i really don't understand this. (i observed that the code does not hang).
2. By clicking the button i have made my_flag TRUE so in the thread it should go to the function readinputstatuschangeLedColourtoGreen execute it, after executing the my_flag is made FALSE. will the program automatically go to the thread or i need to start again. if i have to start the thread where and how to start the thread.
Sorry for the lengthy mail but please let me know if you did not understand. Your reply would help me to gain little confidence on multithreading.
thanks in advance,
regards,
satya
Bookmarks