For a proper answer, you'd have to post what code you're using already. However, in general, you can avoid freezing the UI by using setTimeout, which you can read about here:
http://ejohn.org/blog/how-javascript-timers-work/.
Basically, do a small bit of work, then call setTimeout so the UI can take control for a few milliseconds before you resume doing more work. Repeat that and you can simulate multiple threads.
EDIT: Here's an example (a number will increment every 30 milliseconds using a timeout rather than a loop):
<html>
<head>
<title>Timer</title>
</head>
<body>
<div id="info">0</div>
<script type="text/javascript">
(function() {
var val = 0;
var fnRepeat;
fnRepeat = function() {
val = val + 1;
var infoElement = document.getElementById("info");
infoElement.removeChild(infoElement.childNodes[0]);
infoElement.appendChild(document.createTextNode(val.toString()));
setTimeout(fnRepeat, 30);
};
fnRepeat();
})();
</script>
</body>
</html>
The same concept can be applied for any operation you would typically perform in a loop.