- <#
- .SYNOPSIS
- This script illustrates the CompareExchange Method
- .DESCRIPTION
- This script creates three values, and calls CompareExchange method,
- and displays the results. The first time, we compare two non-equal values
- so no exchange is done. The second time, the comparison succeeds and the
- value us updated.
- .NOTES
- File Name : Compare-Int32.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/801kt583.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Compare-int32.PS1
- Before 1st call:
- 42
- 69
- 104
- After 1st call, before 2nd
- 42
- 69
- 104
- After 2nd call
- 69
- 69
- 104
- #>
- ##
- # Start of Script
- ##
- # Create 3 int32 values
- [int32] $a=42
- [int32] $b=69
- [int32] $c=104
- # Display values before
- "Before 1st call:";$a,$b,$c
- ""
- # Call CompareExchange and print results
- # This call compares $a with $c, so there are not equal
- $result = [System.Threading.Interlocked]::CompareExchange([ref]$a, $b, $c)
- "After 1st call, before 2nd"
- $a,$b,$c
- ""
- # Call CompareExchange and print results
- # This call compares $a with $A, so this call
- # returns $a updated to $b
- $result = [System.Threading.Interlocked]::CompareExchange([ref]$a, $b, $a)
- "After 2nd call"
- $a,$b,$c
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Showing posts with label System.Threading.Interlocking. Show all posts
Showing posts with label System.Threading.Interlocking. Show all posts
Monday, 6 July 2009
Compare-Int32.ps1
Wednesday, 1 July 2009
Compare-Double
- <#
- .SYNOPSIS
- This script illustrates the CompareExchange Method
- .DESCRIPTION
- This script creates three values, and calls CompareExchange method,
- and displays the results. The first time, we compare to non-equal values
- so no exchange is done. The second time, the comparison succeeds and the
- value us updated.
- .NOTES
- File Name : Compare-Double.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/cd0811yf.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Compare-Double.PS1
- Before 1st call:
- 42.42
- 69.69
- 104.4
- After 1st call, before 2nd
- 42.42
- 69.69
- 104.4
- After 2nd call
- 69.69
- 69.69
- 104.4
- #>
- ##
- # Start of Script
- ##
- # Create 3 double values
- [double] $a=42.42
- [double] $b=69.69
- [double] $c=104.4
- # Display values before
- "Before 1st call:";$a,$b,$c
- ""
- # Call CompareExchange and print results
- # This call compares $a with $c, so there are not equal
- $result = [system.Threading.Interlocked]::CompareExchange([ref]$a, $b, $c)
- "After 1st call, before 2nd"
- $a,$b,$c
- ""
- # Call CompareExchange and print results
- # This call compares $a with $A, so this call
- # returns $a updated to $b
- $result = [system.Threading.Interlocked]::CompareExchange([ref]$a, $b, $a)
- "After 2nd call"
- $a,$b,$c
Subscribe to:
Posts (Atom)