Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

c++ - XinitThread and libfltk

I am compiling code with an interface with FLTK, I need to be able to fork a callback because it's taking parameters from a form an launch work when hitting 'run'. I cannot use a fork at the start of the function to have one thread coming back to the UI instantly, it is said that XInitThreads() is run without argument and returns zero on failure, any other is success. My check don't show up XInitThreads returning 0, so this part is working. Yet I still got an error:

[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.
rc: ../../src/xcb_io.c:260: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.

And this appears two time as one per launched threads.

I assert the call with:

if(XInitThreads() == 0)
{
    fprintf(stderr, "Warning ! No forking available.
");
}

Warning doesn't appear.

Using ubuntu 20.10
g++
FLTK-1.1
ARCH amd64


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

//by using sdt::thread.

Fl_Button b;
b.callback(wrapper, data);

void wrapper(Fl_Widget *w, void *v) {
    std::thread th(task, v);
    th.detach();
} 

the wrapper function starts a thread and we don't join inside of the callback function, or at all.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...