FLTK logo

Re: [fltk.general] Re: Window is frozen

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Re: Window is frozen Ian MacArthur Nov 29, 2021  
 
On Monday, 29 November 2021 at 09:02:06 UTC Manolo wrote:

 I believe the error is in that function, output(), in the call to Fl::awake().
The memory storage of the 2nd argument sent to Fl::awake is unstable, it can be reused at any time
after return from the Fl::awake() function.

Change that 2nd argument to a form where you control the lifetime of this char array, and make sure it's not
changed until it's been used by the main thread.

 Yes - I agree with Manolo.
As I said earlier "threads are hard". 
The key point here is that the output() function will be called "now" in the context of the worker thread, and the passed string s will hold the expected value at that time.
However, the awake() function will be called "later" in the main context, at which point the string it is passed (via the void *v) may have expired and you get rubbish instead.
You need to ensure that any parameters passed to the awake() function have a lifetime sufficient for the purpose.

The asynchronous nature of threads can be challenging....


--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/9b070d04-283e-4006-a6e9-9c743ea48910n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.