From kde-devel Mon Jul 19 04:28:02 2004 From: B S Prabhakar Date: Mon, 19 Jul 2004 04:28:02 +0000 To: kde-devel Subject: Re: synchronization problem in libkhtml while doing a form submit Message-Id: <40FB4B02.6040207 () yahoo-inc ! com> X-MARC-Message: https://marc.info/?l=kde-devel&m=109021050207191 why we should call KDE library only from main thread ? Is there any dependency in KDE library on main thread ? We have a requirement where in the KHTML related operation is to be done in a plugin which is called by thirdparty application. here we don't have access to main thread. How to proceed in this situation with KDE library. We are running event loop in one worker thread and KHTML related in other worker threads (Multiple threads) . Is this mode of working not supported / adviceable with KDE ? Our code just calls openURI in a loop. We are facing frequent crash in our application, Attached is the sample which we used to test KHTMLPart openURI by multiple (2 worker threads) threads which crashed frequently Most of the time crash happened after a while since program start (stack dump for the same is attached) but some times application crashed soon after starting while executing connect API **************************************************************************************************** #include "kjscript.h" #include #include #include #include #include #include #include #include #include using namespace DOM; static bool g_initialized = false; int argc; char * argv[1]; //static KApplication a(NULL,argc, argv, "p4" ,false,false); KJScript::KJScript():QObject() { this->part = new KHTMLPart(); this->m_jscript = false; // set defaults this->part->setJScriptEnabled(1); this->part->setJavaEnabled(1); this->part->setPluginsEnabled(1); this->part->setAutoloadImages(1); // PAGE URL Request QObject::connect(this->part->browserExtension(), SIGNAL(openURLRequestDelayed(const KURL &, const KParts::URLArgs &)), this, SLOT(SlotOpenURL(const KURL &))); // KHTMLPart::FormNotification formNfn=KHTMLPart::Before; KHTMLPart::FormNotification formNfn=KHTMLPart::Only; this->part->setFormNotification(formNfn); QObject::connect( this->part, SIGNAL( completed() ), this, SLOT( documentCompleted() ) ); QObject::connect( this->part, SIGNAL(formSubmitNotification(const char *, const QString& , const QByteArray& , const QString& , const QString& , const QString& )),this,SLOT(formSubmit(const char *, const QString& , const QByteArray& , const QString&, const QString&, const QString&)) ); QObject::connect(this,SIGNAL(formSubmitsignal()),this,SLOT(handleForm()) ); } KJScript::~KJScript() { if (this->part) delete this->part; } DOM::HTMLDocument KJScript::getHtmlDocument(void) { if(this->part) return this->part->htmlDocument(); } void KJScript::documentCompleted(void) { cout << "Document completed without pending action"<m_waitcond.wakeOne(); } void KJScript::documentCompleted(bool completed) { cout << "Document completed ==>"<m_waitcond.wakeAll(); } int KJScript::wait(unsigned long time) { cout <<"Started waiting "<m_waitcond.wait(time); } void KJScript::openURL (const KURL &url ) { cout <<"Opening url =="<< url.url()<part->openURL(url); } class Worker: public QThread { public: Worker() { QThread::start(); } protected: void run() { // a.exec(); cout <<"Event thread exiting"<openURL(url); jscript->wait(ULONG_MAX); delete jscript; } } class Fetcher : public QThread { QString m_filename; public: Fetcher(QString file) { m_filename = file; QThread::start(); } protected: void run() { fetchPage(m_filename.data()); cout <<"Exiting thread Fetcher "<< m_filename <On Wed, 14 Jul 2004, Waldo Bastian wrote: > > >>On Wed July 14 2004 17:33, Yarram Sunil Kumar wrote: >> >> >>> I have changed my code and running the QApplication::exec() in >>>main thread. There are other worker threads that does fetching (calls >>>openURL). >>>Each thread reads a list of urls and fetches them sequentially. >>> >>> >>DCOP (or KDE for that matter) does not support multiple threads. >> >> > >That's an awfully broad statement to make. And untrue, since you can see >KNode using threads quite successfully for several years now (KPilot does, >too). The KDE libraries are not designed to be reentrant, though, so you >have to be _very_ careful what you do with the libraries from other >threads; basically, if it crashes, then you did something you shouldn't >have. Use threads for computation - call KDE libraries only from the main >thread. > > > > > >>>Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << >>> >>> > > > > > >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<