R
R
Robotex2011-04-26 13:47:34
Nginx
Robotex, 2011-04-26 13:47:34

Qt4 QThread: sharing data between threads?

There is a server program in which many threads (thousands of them) are running. How can I get access from one thread to another without using signals / slots (if thousands of threads simultaneously send a signal to other threads and to each other, then I think it will be very slow). One thread can send any information to the second one (the first one initiates the creation of the second one) via JSON. But here's how to send JSON to the spawned stream first? What should the first one pass to it when it is created so that it can instantly access it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ighor July, 2014-12-05
@Robotex

Thousands of threads is not a good way to optimize a program.
QThreadPool should be used and the number of threads is about twice the number of physical cores.

M
mt_, 2011-04-26
@mt_

If you are not prompted by people who are well versed in Kute, then you can try my version, which I have been using in practice for more than a year:

class UserThreadNotify
{
public:
    virtual void OnSomeNotification(/*args*/);
};

class UserThread
{
public:
    UserThread(UserThreadNotify *notify) :notify(_notify) {}
private:
    void OnSomeEvent() { notify->OnSomeNotification(/*args*/); }
    UserThreadNotify *notify;
};

class GeneralThread : public UserThreadNotify
{
public:
    virtual void OnSomeNotification(/*args*/) {/*...*/}
private:
    void CreateUserThread() {/*...*/ UserThread(this);}

};

R
Robotex, 2011-04-27
@Robotex

Here is an application. It has QTcpServer. Each time you connect to tcpServer, a new trade is created containing a QTcpSocket. So, how can two threads (and there may be millions of them) exchange data?
I tried to send a signal to the server, and from there to all threads and check the id in the slot - it does not work correctly like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question