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.


>
> 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

Reply via email to