Skip to content

Commit

Permalink
doc: encourage use of the handler thread to avoid race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
mflatt committed May 30, 2022
1 parent 88258d0 commit 22c06cd
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions gui-doc/scribblings/gui/win-overview.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -898,12 +898,28 @@ When a handler thread shows a dialog, the dialog's @method[dialog%

Windowing functions and methods from @racketmodname[racket/gui/base]
can be called in any thread, but beware of creating race conditions
among the threads or with the handler thread. Graphical objects are
thread-safe, but callbacks or other event handlers might see changing
object states if graphical elements are manipulated in multiple
threads. Editor classes have more significant thread constraints; see
@secref["editorthreads"].

among the threads or with the handler thread:

@itemlist[

@item{Although graphical objects are thread-safe, callbacks or other
event handlers might see changing object states if graphical
elements are manipulated in multiple threads.}

@item{Editor classes have specific threading constraints. See
@secref["editorthreads"].}

]

Because it's easy to create confusing race conditions by manipulating
GUI elements in a non-handler thread (while callbacks might run in the
handler thread), it's best to instead perform all GUI setup and
manipulations in the handler thread. The @racket[queue-callback]
function can be helpful to schedule work in the handler thread from
any other thread. When already running in the handler thread, use
@racket[yield] to wait on non-GUI events while allowing GUI events to
proceed.


@subsection[#:tag "currenteventspace"]{Creating and Setting the Eventspace}

Expand Down

0 comments on commit 22c06cd

Please sign in to comment.