Image *im=ImageFromFile("c:\\programs\\example36\\porkpie.bmp"); if (im==NULL) { print("Error reading graphics file: "); print(GetReasonForFailure()); newline(); return; } DrawImage(im, 100, 100); DrawImage(im, 200, 100); DrawImage(im, 300, 100);
void background(int init) { for (int val=init; val<init+10; val+=1) { Delay(random_in_range(0.1, 2.0)); printf("%d ", val); } printf("done "); } void main(void) { Thread one(background); Thread two(background); printf("go! "); one.Start(10); two.Start(20); Delay(10.0); printf("end "); }
{ sem.WaitUntilClearThenSet(); int temp=x; temp=temp+x; temp=temp-1; x=temp; sem.Clear(); }A Semaphore may be either clear or set. "clear" means "OK to proceed"; "set" means "danger: wait". Before using a shared variable, a thread must wait until the semaphore is clear, then set that semaphore so that no other thread may proceed. After using the shared variable, that thread must clear the semaphore otherwise no other thread will be able to continue.