- <#
- .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
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Wednesday 1 July 2009
Compare-Double
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment