Hey guys. to controle my machines i use vix 1.0 with vmware-server. in sme documents i've read, that this version should be thread safe, but my application c/c++ crashes each time, when i call a vix functions. can someone help?
Can you process a VIX_HostConnect?
If not, check if you are using the proper DLL's that fir to your installed VMware Server/Worktation product.
Can you process a VIX_HostConnect?
If not, check if you are using the proper DLL's that fir to your installed VMware Server/Worktation product.
yeah. in a single thread - my code works fine. no problems.
pls see my code.... http://phpfi.com/342066
Maybe i've an old version? i use the vix api from the latest vmware-server 1.0.6 installation.
VC++ 8 | Windows XP..
i think the problem is definitly the multithreading...
Took a look at your code.
EnterCriticalSection() and LeaveCriticalSection() are direct Windows API calls, but this has nothing to do with multithreading.
I'am programming with PowerBasic and also use CriticalSection-Calls, but not while accessing VIX-functions, only when setting global variables.
Besides. Vix_HostConnect delivers a hosthandle, you can use this value all of the time everywhere in your program (if global), no need to encapsulate in a critical section.
(1) call Vix_HostConnect
(2) define a function you can use multithreaded (detecting powerstate or so)
(3) call your mt-function with virtual machine A
(4) call your mt-function with virtual machine B
Use critical sections within the mt-functions to change variables (e.g. virtual machine power state or so; maybe you stored this to an array)
Okay that means, i have to wrap all orginal VIX functions for multithreading using critical sections?
You have to wrap the VIX functions for multithreading.
You have to wrap variable-accesses with critical sections. This can be within your VIX-functions or any other code.
VIX functions are threadsafe, this means you don't have to care if you are calling a VIX function from a main program, or from a threaded function.
Personally i don't like critical sections, because it takes a long time. I've compared critical section with a simple long integer variable locking mechanism, my version works 10 times faster.
If you have some BASIC knowledge, have fun with this:
'----
' Function GLock
' locking for global variables
' in 0 => reset
' -1 => set lock, wait infinitely
' out %True => lock/reset success
' %False => lock failed
'----
Function GLock(Opt ByVal Init As Long ) As Long
Static LockVar As Dword
Local lResult As Long
Local cnt As Long
'initialize/reset lock
If Init = 0 Then
lResult = InterlockedExchange( LockVar, 0 )
Function = %True
Exit Function
End If
'set lock
If Init < 0 Then
Do While LockVar <> 0
Sleep 10
Loop
lResult = InterlockedIncrement( LockVar )
Function = %True
End If
'wait for lock
If Init > 0 Then
cnt = 0
Do While LockVar <> 0
Sleep 100
Incr cnt
If Init > cnt*10 Then
Function = %False
Exit Function
End If
Loop
Function = %True
End If
End Function
Okay thx. vix functions are thread safe but i've to wrap all "variable-accesses" in safe section like critical-section?
Now you got it.