These are instructions on how to jailbreak your iPhone 3GS using PurpleRa1n for Mac OS X. Once you have completed this tutorial you will be able to unlock your iPhone 3GS using this tutorial.
This is a preliminary jailbreak and thus some apps such as Winterboard will not work. You may want to consider waiting for the jailbreak release from the iPhone Dev-Team if this is important to you.
You can find a Windows version of this tutorial here.