From: anmol....@gmail.com
Sent: 11 November 2021 15:01
To: fltk.general
Subject: [fltk.general] Fl_Preferences instead of boost::interprocess
--
There’s a version of Fl_Preferences::get() that uses void* to get/set any length item. This is an example that gets and sets an object of type time_t.
// Check this is to be a new session (> 1hour after previous session ended
time_t today = time(nullptr);
void* p_last = new time_t;
settings_->get("Session End", p_last, &today, sizeof(time_t));
time_t last_session_end = *(time_t*)p_last;
char action[100];
if (difftime(today, last_session_end) > 3600.0) {
// It is > 60 minutes since we last saved a record - new session
session_start_ = today;
strcpy(action, "Starting new session");
settings_->set("Session Start", &today, sizeof(time_t));
resuming_ = false;
}
else {
// Restore previous session's start time
settings_->get("Session Start", p_last, &today, sizeof(time_t));
session_start_ = *(time_t*)p_last;
strcpy(action, "Resuming session");
resuming_ = true;
}
.
Regards Phil.
There’s a version of Fl_Preferences::get() that uses void* to get/set any length item. This is an example that gets and sets an object of type time_t.
Regards Phil.
From: anmol....@gmail.com
Sent: 15 November 2021 05:55
To: fltk.general
Subject: Re: [fltk.general] Fl_Preferences instead of boost::interprocess
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/5cb4214c-f490-4785-aebc-5711952ffb61n%40googlegroups.com.
I do not yet understand how to use threads.
Phil.
Is this thread safe? I looked in the code, and I'm not sure of concurrency.
From: 'Matthias Melcher' via fltk.general
Sent: 15 November 2021 15:02
To: fltk.general
Subject: Re: [fltk.general] Fl_Preferences instead of boost::interprocess
Fl_Preferences is not thread-safe. Neither for the file-base preferences nor for the internal preference database. It's just a file format reader and write for the super old Microsoft .ini files, representing them as a data tree. It would be more useful if it was updated to XML or JSON, but the API is more geared at unique identifiers.
For thread safe access to any kind of data, you should read up on locks and semaphores. If you do want to use multithreading, there is no way around understanding those. C++17 and up offer all these calls in a very nice cross-platform way as part of the standard library.
My app would benefit from multi-threading. Occasionally it goes off and performs some web activity that then holds up the main tasks. However it would be a major rework to introduce it now. I understand the concepts of locks and semaphores, but not how they are implemented in C++, either pre 17 or 17+.
Regards Phil.
For thread safe access to any kind of data, you should read up on locks and semaphores. If you do want to use multithreading, there is no way around understanding those. C++17 and up offer all these calls in a very nice cross-platform way as part of the standard library.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/f1cc0e89-ca3a-4ea2-ac92-f81a2cf88a58n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/61921ced.1c69fb81.9b10d.e779SMTPIN_ADDED_BROKEN%40gmr-mx.google.com.
Um (hi Ian, Bill ;-) , a few things:
1. threads have thread-local memory, but can still access the global space of the main thread. So if your main thread creates a Mutex, all children can access that thread. Just pass a pointer to the Mutex in the appropriate call.
2. FLTK should always be running in the main thread. You can call FLTK in child threads, but some platforms can not handle window creation or deletion outside of the main thread!
3. Just in case you plan to link FLTK to s dynamically linked library: You can not link FLTK statically multiple times in the same app. If you link FLTK (or any other library) dynamically once, you can't link it again statically.
4. In a previous mail, I understood that you want to use the separate thread to download something across a network. If you want to notify FLTK in the main thread, that your library finished loading, you can use the sequence Fl::lock(); Fl::awake(handle_downloaded_data); Fl::unlock(); in your thread. This will call the handle_downloadPdata(void*) function in your main FLTK thread, which then can do UI stuff. Note: for FLTK locking to work, you must call Fl::lock(); once right before Fl::run();
From: anmol....@gmail.com
Sent: 23 November 2021 03:32
To: fltk.general
Subject: Re: [fltk.general] Fl_Preferences instead of boost::interprocess
For what it’s worth, under Virtual Studio, I can only statically link any library into the final application. Although I access FLTK methods in my own library, they can only be linked when I bring all the .libs together in the application.
Phil.
Only under WinXX. This thread explains the issue - https://stackoverflow.com/questions/19373061/what-happens-to-global-and-static-variables-in-a-shared-library-when-it-is-dynam
For what it’s worth, under Virtual Studio, I can only statically link any library into the final application. Although I access FLTK methods in my own library, they can only be linked when I bring all the .libs together in the application.
From: Ian MacArthur
Sent: 23 November 2021 08:44
To: fltk.general
Subject: Re: [fltk.general] Fl_Preferences instead of boost::interprocess
On Tuesday, 23 November 2021 at 05:49:25 UTC Phil wrote:
It was a typo – too early in the morning after a poor night’s sleep.
I used VS to generate the FLTK static .libs. I used Cygwin to generate a .dll for another library I am using when I wanted the git master. I then used a VS utility to convert this to a static .lib. Normally I just use the static .lib in the released version. Just looked in my project work book but I can’t find the exact process. Other libraries, I am downloading static .lib files from various other projects.
Phil.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/ed311b12-f838-4775-a77d-77e26061d6ffn%40googlegroups.com.
I used VS to generate the FLTK static .libs. I used Cygwin to generate a .dll for another library I am using when I wanted the git master. I then used a VS utility to convert this to a static .lib. Normally I just use the static .lib in the released version. Just looked in my project work book but I can’t find the exact process. Other libraries, I am downloading static .lib files from various other projects.