Thread handling

Before we can correctly handle background processing with Go-GTK (or any GTK+ implementations), we must correctly initialize the thread handling portions of the underlying libraries (glib and gdk). These lines should be entered at the start of an application's main() function:

glib.ThreadInit(nil)
gdk.ThreadsInit()
gdk.ThreadsEnter()
gtk.Init(nil)

Once the thread handling has been set up, we can write background code that will communicate with the user interface. This code must execute on the same thread that the application was created with. To ensure this, we use the helper functions, gdk.ThreadsEnter() and gdk.ThreadsLeave(), around the code we wish to execute. For our application to add new messages to the end of our email list when they arrive, add the following code immediately before calling gtk.Main() to start the application:

   go func() {
for email := range server.Incoming() {
gdk.ThreadsEnter()
main.prependEmail(email)
gdk.ThreadsLeave()
}
}()

This completes the implementation of our GoMail application in Go-GTK, but how can we compile the app for different platforms?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.218.221