-
Notifications
You must be signed in to change notification settings - Fork 18
Description
Hai thetrik,
To test multithreading using modMultThreading2.bas I made a
standard exe project containing form1,module Module1 with global variable gi and added your
modMultiThreading2.bas.
Form1 code
Private Sub Command1_Click()
gi = 12
vbCreateThread 0, 0, AddressOf abc, 0, 0, 0
End Sub
Private Sub Command2_Click()
MsgBox "in th abc gi= " & gi
End Sub
Private Sub Form_Load()
modMultiThreading.Initialize
End Sub
Private Sub Form_Unload(Cancel As Integer)
modMultiThreading.Uninitialize
End Sub
module1 code
Public gi As Long
Public Function abc( _
ByVal tThreadData As Long) As Long
MsgBox "in th abc gi= " & gi
gi = 70
End Function
The following code is commented from CreateVBHeaderCopy function of modMultThreading2.bas and placed in CreateVBHeaderCopywithoutglobalChange() in order to check effect on global variable.CreateVBHeaderCopywithoutglobalChange is called instead of CreateVBHeaderCopy from ThreadProc in modMultiThreading2,bas.But the gi global variable behaves the same independent of the below code.Please explain with an example how the below code effects global and static variables as I am unable to understand its use in an example practically.
' // In order to keep global variables
' // Change the [vbheaderglobalvarsexperiment.zip](https://github.com/thetrik/VbTrickThreading/files/14648354/vbheaderglobalvarsexperiment.zip), VbPublicObjectDescriptor.lpStaticBytes
pProjInfo = pHeader + &H6A
CopyMemory ByVal pProjInfo, ByVal pOldProjInfo, &H23C
' // Update on VBHeader
GetMem4 pProjInfo, ByVal pHeader + &H30
' // Create copy of Object table
pObjTable = pProjInfo + &H23C
CopyMemory ByVal pObjTable, ByVal pOldObjTable, &H54
' // Update
GetMem4 pObjTable, ByVal pProjInfo + &H4
' // Allocate descriptors
pDescriptors = pObjTable + &H54
CopyMemory ByVal pDescriptors, ByVal pOldDesc, lModulesCount * &H30
' // Update
GetMem4 pDescriptors, ByVal pObjTable + &H30
' // Allocate variables block
pVarBlock = pDescriptors + lModulesCount * &H30
For lIndex = 0 To lModulesCount - 1
' // Zero number of public and local variables
GetMem4 pVarBlock, ByVal pDescriptors + lIndex * &H30 + &H8
GetMem4 0&, ByVal pDescriptors + lIndex * &H30 + &HC
Next
Project attached
vbheaderglobalvarsexperiment.zip
Simi