The initial setting in the main thread of the working page and the visible page (by 'Screenset') is not taken into account in the user threads nevertheless created after the setting.
The initial setting for the working page and the visible page ('ScreenSet work_page, visible_page') must be duplicated at the beginning of each thread which want work with a multi-pages configuration (for double buffering method).
A demonstrative example, in order to well highlight the problem:
- In each thread (the main thread for displaying a counter and a user thread for displaying the date), the display is first blanked followed by a temporization, before the update.
- Therefore only the good usage of the work and visible pages plus 'Screencopy' allows to avoid the flickering for the two displayings.
- One can check that each thread displays without flickering only if it begins with its own 'Screenset' (check by putting in comment each line 'Screenset 1, 0').
Dim As Any Ptr pt
Dim Shared As Any Ptr pm
Dim Shared As Integer quit
Sub ProcedureThread (Byval param As Any Ptr)
Screenset 1, 0
Do
MutexLock(pm)
Locate 1, 70
Print Space(10);
Locate 2, 71
Print Space(8);
Sleep 150
Locate 1, 70
Print Date;
Locate 2, 71
Print Time;
Screencopy
MutexUnlock(pm)
Sleep 20
Loop Until quit = 1
End Sub
Screen 12, , 2
Screenset 1, 0
Locate 30, 2
Print "<any_key> : exit";
pm = MutexCreate
pt = ThreadCreate(@ProcedureThread)
Dim As String s
Do
Static c As Integer
MutexLock(pm)
Locate 15,40
Print Space(6);
Sleep 200
Locate 15,40
Print Using "######"; c;
Screencopy
s = Inkey
MutexUnlock(pm)
c = (c + 1) MOD 1000000
Sleep 20
Loop Until s <> ""
quit = 1
ThreadWait(pt)
MutexDestroy(pm)
Referring to forum, from the post:
http://www.freebasic.net/forum/viewtopic.php?p=213554#p213554
Main post:
http://www.freebasic.net/forum/viewtopic.php?p=214839#p214839
Upon reflection, I wonder if it is not better that each thread has its own setting for the current working page.
Last edit: fxm (freebasic.net) 2016-08-14
The source code of gfxlib2 uses TLS (Thread Local Storage) to store many states, so many things are thread-specific like SCREENSET (and also VIEW settings, graphic cursor position, graphic colors, ...).
So the graphics statements (including also Draw String) are thread-safe and have normally their own states in local.
I think that we can now close this bug report.
The comment:
reminds me that commit [58a79546e976d50b8e10012584e61295c1ecfefc] adds new data that is not in TLS.
So, while the primary issue of this bug report could probably solved through documentation, I believe there is still more to inspect at the code level.
Related
Commit: [58a795]