PDA

View Full Version : Find an allready running instances of a thread and connect to it



Roman
12th November 2012, 18:14
Is it possible to to search for an allreay running instance of for example a thread and ''connect'' to it?
Something like this:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
wnThread *th = find(wnThread);
if(th = NULL){
wnThread *th = new wnThread();
th->start();
}
return a.exec();
}

I know about dde in Windows but i need a solution for independent operatingsystems.

Thanks

amleto
12th November 2012, 19:19
No, not that I know of.

You have a simple problem, though. Use a factory to make all your threads and then you will only need a very simple observer mechanism to obtain knowledge of the running state of all threads.


Can I put it to you that your question is not a 'good' one, though? By that I mean you are asking

'I want to do X (because I think it is a solution to my problem). How do I do it?',

but you would probably be better of asking

'My problem is Y, what is a good way to solve it?'

Roman
12th November 2012, 22:15
No, not that I know of.

You have a simple problem, though. Use a factory to make all your threads and then you will only need a very simple observer mechanism to obtain knowledge of the running state of all threads.


Can I put it to you that your question is not a 'good' one, though? By that I mean you are asking

'I want to do X (because I think it is a solution to my problem). How do I do it?',

but you would probably be better of asking

'My problem is Y, what is a good way to solve it?'
Ok will try the other way round:
I've got a Hardware-Device which can be attached to the computer. So far so good, but its driver just let me communicate by one programm. Since I'd like to process data from the device by two or even more programms simultaneously it would be great to have somekind of data-exchange programm. Hope you understand me.

amleto
12th November 2012, 23:28
ok, so you want a server to fork the data. Networking's not really my thing, but I don't see where are the threads come in. You'll just be reading data from your device socket, and then posting it on multiple sockets for your other apps.

Roman
13th November 2012, 09:24
ok, so you want a server to fork the data. Networking's not really my thing, but I don't see where are the threads come in. You'll just be reading data from your device socket, and then posting it on multiple sockets for your other apps.
Well its not quiet a Server its more an eeprom attached via usb. Its data is needed in sever applications. So the question is how to build a "Software-sever" that can be connected by an other Software.

amleto
13th November 2012, 12:43
use sockets/networking classes in Qt. It is a well-trodden path, and it won't need any 'funny business' searching for zombie/daemon/headless threads