On Apr 18 2018, Matt Welland wrote:
On Wed, Apr 18, 2018 at 1:23 AM, Jörg F. Wittenberger <
[email protected]> wrote:
Hi,
just my two cents.
On Apr 16 2018, Eric Wing wrote:
This is a proposal to introduce a way to post and run events on the
main UI thread.
Currently (as far as I know), IUP is hands-off on threads.
...
It's easy to see the problem you're facing.
I'm no IUP expert, however I'm pretty positive that this can be solved
without introducing another API.
In a similar situation I have been able to abstain from using the
complete IUP abstraction around the main loop and resort to using
IupFlush() instead. Doing so allows to queue requests from other threads
for execution in the GUI thread, which processes said queue right before
calling IupFlush().
Once I had these roughly 40 lines of code in place begin factoring out
IupFlush()s and run them just once before IupFlush() to reduce some
flickering.
Maybe such an approach can work for you too.
Hi Jörg, this approach sounds really interesting. Can you provide a little
more detail to clarify how this works? Do you put calls to set attribute in
the queue and then periodically execute the calls in the queue followed by
an IupFlush? I tried this (using the Chicken Scheme IUP binding) and it
seems to work well but I'm concerned there are corner cases to be accounted
for. My (probably naive) test implementation of your approach is pasted
below.
Hi Matt,
Exactly that's what I did. (Slightly more elaborate than your example code,
e.g. using a configurable sleep time and not using thread-sleep! but
waiting with timeout on a condition-variable, which has the added advantage
that urgent signals can easily terminate the wait by signaling the
condition variable, while non-critical changes may be postponed until the
regular update takes place.)
But the principle is the same.
Yes, you are right, there can be corner cases. You really, really want to
be sure that your Iup callbacks don't capture continuations. But it is a
while ago that this was fixed right in the iup egg. From your code I'm
afraid another such corner case would be whether or not you empty the queue
one-by-one (as I would suggest) or all at once. Your case of doing the
latter but flushing the queue only _after_ processing it looks a bit error
prone to me.
BEst
/Jörg
Best
/Jörg
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users
;; trial of replacing iup:main-loop with a queue
(use (prefix iup iup:) srfi-18)
(define *queue* '())
(define *queue-mutex* (make-mutex))
(define (process-queue)
(for-each (lambda (entry)(entry))(reverse *queue*))
(print "processed queue")
(set! *queue* '()))
(define (iattr . params)
(mutex-lock! *queue-mutex*)
(if (not (null? *queue*))
(process-queue))
(let ((result (apply iup:attribute params)))
(mutex-unlock! *queue-mutex*)
result))
(define (iattr-set! . params)
(mutex-lock! *queue-mutex*)
(set! *queue* (cons (lambda ()(apply iup:attribute-set! params))
*queue*))
(mutex-unlock! *queue-mutex*))
(define button1 (iup:button
"Push me"
action: (lambda (o)
(print "Got here at " (current-seconds))
(iattr-set! o "BGCOLOR" "255 255 255"))))
(define tl (iup:show
(iup:dialog
(iup:vbox
button1
(iup:button "Exit" action: (lambda (o)(exit)))))))
(define (main)
(let* ((th1 (make-thread (lambda ()
(let loop ()
(mutex-lock! *queue-mutex*)
(process-queue)
(mutex-unlock! *queue-mutex*)
(iup:main-loop-flush)
(thread-sleep! 1) ;; use a really long delay just for
illustration
(loop)))
"flush loop"))
(th2 (make-thread (lambda ()
(let loop ()
(print "set to green")
(iattr-set! button1 "BGCOLOR" "70 249 73")
(thread-sleep! 0.2)
(print "set to red")
(iattr-set! button1 "BGCOLOR" "253 33 49")
(thread-sleep! 0.2)
(loop)))))
(th3 (make-thread (lambda ()
(let loop ()
(print (iattr button1 "BGCOLOR"))
(thread-sleep! (random 5))
(loop))))))
(thread-start! th1)
(thread-start! th2)
(thread-start! th3)
(thread-join! th1)))
(main)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users