Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6866869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:14:19+00:00 2026-05-27T03:14:19+00:00

I would like to use the Fl::awake(callback) function to call functions from my main

  • 0

I would like to use the Fl::awake(callback) function to call functions from my main loop in an FLTK program. I am calling Fl::awake from a child thread, it returns 1 (success), but my function never gets called. I am calling Fl::wait() in a loop in the main thread. Is there any way i can troubleshoot this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:14:19+00:00Added an answer on May 27, 2026 at 3:14 am

    Code below is an example of a relatively simple FLTK 1.3 application which uses Fl::awake(callback) . The code is from the FLTK’s test directory. Just fetch the source, and you’ll find numerous examples. You did not give us your code, but I assume you did not call Fl::lock(), and later Fl::unlock() in your thread. It is essential because you should not access widgets outside that section…

    include

    #if HAVE_PTHREAD || defined(WIN32)
    #  include <FL/Fl.H>
    #  include <FL/Fl_Double_Window.H>
    #  include <FL/Fl_Browser.H>
    #  include <FL/Fl_Value_Output.H>
    #  include <FL/fl_ask.H>
    #  include "threads.h"
    #  include <stdio.h>
    #  include <math.h>
    
    Fl_Thread prime_thread;
    
    Fl_Browser *browser1, *browser2;
    Fl_Value_Output *value1, *value2;
    int start2 = 3;
    
    void magic_number_cb(void *p)
    {
      Fl_Value_Output *w = (Fl_Value_Output*)p;
      w->labelcolor(FL_RED);
      w->redraw_label();
    }
    
    void* prime_func(void* p)
    {
      Fl_Browser* browser = (Fl_Browser*) p;
      Fl_Value_Output *value;
      int n;
      int step;
      char proud = 0;
    
      if (browser == browser2) {
    n      = start2;
    start2 += 2;
    step   = 12;
    value  = value2;
      } else {
    n     = 3;
    step  = 2;
    value = value1;
      }
    
      // very simple prime number calculator !
      //
      // The return at the end of this function can never be reached and thus 
      // will generate a warning with some compilers, however we need to have 
      // a return statement or other compilers will complain there is no return 
      // statement. To avoid warnings on all compilers, we fool the smart ones 
      // into beleiving that there is a chance that we reach the end by testing 
      // n>=0, knowing that logically, n will never be negative in this context.
      if (n>=0) for (;;) {
    int pp;
    int hn = (int)sqrt((double)n);
    
    for (pp=3; pp<=hn; pp+=2) if ( n%pp == 0 ) break;
    if (pp >= hn) {
      char s[128];
      sprintf(s, "%d", n);
    
      // Obtain a lock before we access the browser widget...
      Fl::lock();
    
      browser->add(s);
      browser->bottomline(browser->size());
      if (n > value->value()) value->value(n);
      n += step;
    
      // Release the lock...
      Fl::unlock();
    
      // Send a message to the main thread, at which point it will
      // process any pending redraws for our browser widget.  The
      // message we pass here isn't used for anything, so we could also
      // just pass NULL.
      Fl::awake(p);
      if (n>10000 && !proud) {
        proud = 1;
        Fl::awake(magic_number_cb, value);
      }
    } else {
      // This should not be necessary since "n" and "step" are local variables,
      // however it appears that at least MacOS X has some threading issues
      // that cause semi-random corruption of the (stack) variables.
      Fl::lock();
      n += step;
      Fl::unlock();
    }
      }
      return 0L;
    }
    
    int main(int argc, char **argv)
    {
      Fl_Double_Window* w = new Fl_Double_Window(200, 200, "Single Thread");
      browser1 = new Fl_Browser(0, 0, 200, 175);
      w->resizable(browser1);
      value1 = new Fl_Value_Output(100, 175, 200, 25, "Max Prime:");
      w->end();
      w->show(argc, argv);
      w = new Fl_Double_Window(200, 200, "Six Threads");
      browser2 = new Fl_Browser(0, 0, 200, 175);
      w->resizable(browser2);
      value2 = new Fl_Value_Output(100, 175, 200, 25, "Max Prime:");
      w->end();
      w->show();
    
      browser1->add("Prime numbers:");
      browser2->add("Prime numbers:");
    
      // Enable multi-thread support by locking from the main
      // thread.  Fl::wait() and Fl::run() call Fl::unlock() and
      // Fl::lock() as needed to release control to the child threads
      // when it is safe to do so...
      Fl::lock();
    
      // Start threads...
    
      // One thread displaying in one browser
      fl_create_thread(prime_thread, prime_func, browser1);
    
      // Several threads displaying in another browser
      fl_create_thread(prime_thread, prime_func, browser2);
      fl_create_thread(prime_thread, prime_func, browser2);
      fl_create_thread(prime_thread, prime_func, browser2);
      fl_create_thread(prime_thread, prime_func, browser2);
      fl_create_thread(prime_thread, prime_func, browser2);
      fl_create_thread(prime_thread, prime_func, browser2);
    
      Fl::run();
    
      return 0;
    }
    #else
    #  include <FL/fl_ask.H>
    
    int main() {
      fl_alert("Sorry, threading not supported on this platform!");
    }
    #endif // HAVE_PTHREAD || WIN32
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using AdoNetAppender (SQL server) in my asp.net application and would like use
I would like to use a language that I am familiar with - Java,
I would like to use something like CLR Profiles on .Net 2.0 to see
I would like to use as and is as members of an enumeration. I
I would like to use a component that exposes the datasource property, but instead
I would like to use client-side Javascript to perform a DNS lookup (hostname to
I would like to use javascript to develop general-purpose GUI applications. Initially these are
I would like to use my laptop as a web development (PHP, Python, etc.)
I would like to use Emacs to edit some VB6 files but Emacs does
I would like to use VB9 but am not sure what syntax to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.