Я слышал насчет потоков, но не понимаю как они работают и как с ними работать в wxWidgets.
Можете обьяснить мне, а лучше с примером что это такое?
class MySignallingThread : public wxThread
{
public:
MySignallingThread(wxMutex *mutex, wxCondition *condition)
{
m_mutex = mutex;
m_condition = condition;
Create();
}
virtual ExitCode Entry()
{
... do our job ...
// tell the other(s) thread(s) that we're about to terminate: we must
// lock the mutex first or we might signal the condition before the
// waiting threads start waiting on it!
wxMutexLocker lock(*m_mutex);
m_condition->Broadcast(); // same as Signal() here -- one waiter only
return 0;
}
private:
wxCondition *m_condition;
wxMutex *m_mutex;
};
int main()
{
wxMutex mutex;
wxCondition condition(mutex);
// the mutex should be initially locked
mutex.Lock();
// create and run the thread but notice that it won't be able to
// exit (and signal its exit) before we unlock the mutex below
MySignallingThread *thread = new MySignallingThread(&mutex, &condition);
thread->Run();
// wait for the thread termination: Wait() atomically unlocks the mutex
// which allows the thread to continue and starts waiting
condition.Wait();
// now we can exit
return 0;
}
Спасибо, а можно на словах, просто я не программер, а админ, да и там слишком много читать нужно, чтобы понять что к чему...
На словах не стоит потому как в книжке описано достаточно хорошо, и не так уж и много там читать, всего 1 главу о потоках.
Какая разница админ ты или программер, если хочешь работать с потоками, должен знать как они себя ведут и что из себя представляют.
Форум Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)