Re: Threads [Was: Re: 64 bit euphoria]
- Posted by Patrick Barnes <mrtrick at gmail.com> Apr 26, 2005
- 550 views
On 4/26/05, Pete Lomax <petelomax at blueyonder.co.uk> wrote: > OK: GENERAL QUESTION TO ALL: > > If there was something you wanted threads for, what would it look like > in your ideal snippet of Euphoria code? The thing that a true threaded model can offer that a simulated model can NEVER offer is preemptive multitasking (as opposed to cooperative) Ideally, a 'thread' would be similar to a procedure or function declaration. A few other things like semaphore (wait and signal) and mutex support would be nice too. An example: integer mutex_job=20 thread long_processing_job( sequence data ) --Do lots of processing on data, this takes a long time. ... mutex_job += 1 end thread ...lots of windows code. procedure onButtonClick(id, event, params) if mutex_job then mutex_job = 0 long_processing_job(data) end if end procedure procedure onTimer(id, event, params) if mutex_job then setText(text, "complete!") end if end procedure ...other windows code For instance, here is a function(originally) called long_processing_job. While iterative, there's no easy way to insert doEvents(0) calls, as at one level it's called too often, and at the next level it may not be called enough. This code snippet allows the program to remain responsive to the user, while the processing is being done. A more mature thread implementation might support one thread triggering a windows API event in the first, rather than being polling. -- MrTrick ----------