|
|
On 2/28/21 7:41 AM, imm wrote:
On Sun, 28 Feb 2021, 13:46
Gonzalo Garramuño wrote:
Is there
a function to determine whether a piece of code is running
on
the main fltk's thread?
Seems like a non-FLTK question.. this has more to do with the
thread library you're using,
e.g. pthreads.
Under Win32 that's a call to GetCurrentThreadID(),
can't remember the pthread equivalent off the top of my head,
but it seemed to work anyway!
I googled for 'pthreads determine main thread'.. seems it might
be platform specific:
https://stackoverflow.com/questions/4867839/how-can-i-tell-if-pthread-self-is-the-main-first-thread-in-the-process
I imagine if pthread_self() is the way to get the current thread
ID, then just save that
value early in your main(), before you start any child threads,
and save the value to
a global, then compare that global to pthread_self() later in
your code, e.g.
// main.c
pthread_t G_main_tid; // GLOBAL: main thread's
ID
..
int main() {
..
G_main_tid = pthread_self(); // save main thread's
ID
..
}
void some_function() {
if ( G_main_tid == pthread_self() ) {
// main thread
} else {
// child thread
}
}
--
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/6f1a9f7e-50ce-a72d-fe38-6ed5560e5fb2%40seriss.com.
[ Direct Link to Message ] | |
|
| |