From: Simon G. <ga...@cs...> - 2004-04-30 21:19:16
|
Actually this is exreamly easy compared to what you would have to do to use the POSIX threading functions and C++ objects. I think the difficulty is that the abstract model that this code represents is not clear to you. The model essentially abstracts threads to classes, i.e. a Looper (named because it sits there in an infinite loop waiting), and allows each class to communicate with discrete packages called Messages. The Looper sits and waits for Messages that it then processes (consumes) to do something based on the contents of the message. What you need to know is that each Looper runs in its own independed thread from any other thread. There are not method calls, just sending discrete messages between threads. This makes synchronization easy, just don't do any between Loopers and everything will be fine... =) > Is there no easier way to do this?? > > On Fri, 2004-04-30 at 21:57 +0200, Henrik Isaksson wrote: > > The reason you can't find a simple example is that it's not an easy thing to > > do... :o( > > > > I haven't tried this myself, it might still work though, however unlikely it > > may seem... .o) > > > > 1. Create a subclass of Looper. > > > > 2. Override HandleMessage() (NOT Run(), Run() handles the messages). > > > > 3. Implement the "computing task" (in this case, your popen(build) thing) in > > HandleMessage(). eg. > > > > void HandleMessage( Message* pcMsg ) > > { > > if( pcMsg->GetCode() == MSG_GET_TO_WORK ) { > > // Do stuff > > } > > } > > > > 4. From your GUI, send (not post) a message to your Looper-descendant class > > to start the computing task in question. > > > > Messenger* pcMsgr = new Messenger( myLooper, myLooper ); > > pcMsgr->SendMessage( new Message( MSG_GET_TO_WORK ) ); > > delete pcMsgr; > > > > (IIRC, PostMessage() is synchronous and would block the sending thread until > > it has been processed by the receiver.) > > > > --- > > Kind Regards, > > Henrik Isaksson > > > > > -----Original Message----- > > > From: David Smith [mailto:dav...@bl...] > > > Sent: Friday, April 30, 2004 9:18 PM > > > To: syl...@li... > > > Subject: Re: [Syllable-developer] os::Looper > > > > > > I need a Looper inside which I can put a popen(build) > > > command, in order that the program does not appear to hang, > > > and I can get line by line text output, so I need the looper > > > for a new thread with messaging also. > > > > > > On Fri, 2004-04-30 at 20:42 +0100, Kristian Van Der Vliet wrote: > > > > On Friday 30 April 2004 7:04 pm, David Smith wrote: > > > > > Hi there, it's me again, with my inane questions about > > > the API. Try > > > > > as I may I can't get a looper to work, nor can I > > > understand the Docs > > > > > or find a simple example. please help :'( > > > > > > > > Depends what you're trying to do. You normally never need > > > to create > > > > nor manage a Looper yourself; everything is done for you by classes > > > > such as os::Application and os::Window. Maybe you could > > > explain what you want to do? > > > > :) > > > > > > > > -- > > > > Vanders > > > > http://syllable.sourceforge.net/ > > > > http://www.liqwyd.com > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > > This SF.Net email is sponsored by: Oracle 10g Get certified on the > > > > hottest thing ever to hit the market... Oracle 10g. > > > > Take an Oracle 10g class now, and we'll give you the exam FREE. > > > > http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click > > > > _______________________________________________ > > > > Syllable-developer mailing list > > > > Syl...@li... > > > > https://lists.sourceforge.net/lists/listinfo/syllable-developer > > > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by: Oracle 10g > > Get certified on the hottest thing ever to hit the market... Oracle 10g. > > Take an Oracle 10g class now, and we'll give you the exam FREE. > > http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click > > _______________________________________________ > > Syllable-developer mailing list > > Syl...@li... > > https://lists.sourceforge.net/lists/listinfo/syllable-developer > > > > |