// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <time.h>

#include <windows.h>

#include <conio.h>

#include <iostream>

using namespace std;

CRITICAL_SECTION cs;

void loop1()
{
   char c[] = { '|', '/', '-', '\\', '|', '/', '-', '\\' };
   int i = 0;
   while(true)
   {
      EnterCriticalSection(&cs);   
      gotoxy(40,10);
      cout << c[i % 8];
      cout.flush();
      LeaveCriticalSection(&cs);   
      Sleep(1000);
      i++;
   }
}

void loop2()
{
   while(true)
   {
      EnterCriticalSection(&cs);   
      gotoxy(30,1);
      time_t t = time(NULL);
      cout << ctime(&t);
      cout.flush();
      LeaveCriticalSection(&cs);   
      Sleep(1000);
   }
}

DWORD __stdcall loop1dispatch(void *p)
{
   loop1();
   return 0;
}

DWORD __stdcall loop2dispatch(void *p)
{
   loop2();
   return 0;
}

void threadloop1()
{
   DWORD id;
   CreateThread(NULL,0,loop1dispatch,NULL,0,&id);
}

void threadloop2()
{
   DWORD id;
   CreateThread(NULL,0,loop2dispatch,NULL,0,&id);
}

int main()
{
   InitializeCriticalSection(&cs);   
   clrscr(),
   threadloop2();
   loop1();
   return 0;
}
