Coder Social home page Coder Social logo

Problem with sync.WaitGroup and gtk? about ui HOT 9 CLOSED

andlabs avatar andlabs commented on July 24, 2024
Problem with sync.WaitGroup and gtk?

from ui.

Comments (9)

copiesofcopies avatar copiesofcopies commented on July 24, 2024

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

from ui.

andlabs avatar andlabs commented on July 24, 2024

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

from ui.

copiesofcopies avatar copiesofcopies commented on July 24, 2024

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.

from ui.

copiesofcopies avatar copiesofcopies commented on July 24, 2024

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.

from ui.

copiesofcopies avatar copiesofcopies commented on July 24, 2024

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?

from ui.

copiesofcopies avatar copiesofcopies commented on July 24, 2024

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.

from ui.

andlabs avatar andlabs commented on July 24, 2024

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

from ui.

copiesofcopies avatar copiesofcopies commented on July 24, 2024

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!

from ui.

andlabs avatar andlabs commented on July 24, 2024

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.

from ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.