Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with sync.WaitGroup and gtk? #30

Closed
copiesofcopies opened this issue Sep 18, 2014 · 9 comments
Closed

Problem with sync.WaitGroup and gtk? #30

copiesofcopies opened this issue Sep 18, 2014 · 9 comments

Comments

@copiesofcopies
Copy link

I'm developing on Debian. I'm trying to use sync.WaitGroup in a program using the ui library, and it keeps dumping with this message:

[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.

It could be that I just don't understand what I'm doing yet (quite likely). But I also found this: http://stackoverflow.com/questions/18647475/threading-problems-with-gtk

Call XInitThreads(). This should be done before gtk_init, that will stop the messages!

@copiesofcopies
Copy link
Author

Until further notice, I'm assuming this is a race condition I've created and that I just don't understand concurrency.

@andlabs
Copy link
Owner

andlabs commented Sep 22, 2014

Can you provide some sample code? (I do need to write documentation...)

@andlabs andlabs reopened this Sep 22, 2014
@copiesofcopies
Copy link
Author

Sure, the code is here, and the problem is in main.go. main() starts listAccounts() as a goroutine, and when the user clicks the "Add" button to add a new account, listAccounts() starts editAccount(), passing it the address of an Account struct, then waits for it to finish changing the contents of the struct. My operating assumption is that I need to put a lock in here somewhere.

@copiesofcopies
Copy link
Author

For what it's worth, the race detector didn't find a race here. Here is the full error message I'm getting at the moment.

@copiesofcopies
Copy link
Author

I stripped the program down to its bare essentials: just a window with a button that starts a goroutine to open a second window. The program is still unstable, and crashes with X-related errors like this:

(ui-test:14391): Gdk-WARNING **: ui-test: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.

Or like this longer error. Any idea what might be the problem?

@copiesofcopies
Copy link
Author

And I figured out the problem: you can't open a second window in a goroutine. When I remove "go" from before the call to the function that opens the second window, the crashes disappear.

@andlabs
Copy link
Owner

andlabs commented Sep 23, 2014

Right, you'll need to do ui.Do() in that goroutine call as well.

I really wish I didn't need to use that hacky workaround, but my previous attempts at using channels for events caused lots of problems :(

@andlabs andlabs closed this as completed Sep 23, 2014
@copiesofcopies
Copy link
Author

Oh, I see -- ui.Do() is necessary anytime you call a goroutine that opens a window, not just in main()? I hadn't understood that from the documentation.

Simply dropping "go" and calling it as a normal function seems to be working perfectly well for me so far. Thanks for your replies -- if I can help with documentation, let me know!

@andlabs
Copy link
Owner

andlabs commented Sep 23, 2014

Right, because your code is technically still running in ui.Do() =P The docs need work, yes; I did write a getting started guide on the wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants