Hi,
I am trying to control the movement of a graphics image across the screen, and was hoping of some advice on the matter.
As the image crosses the bridge, I use the first line in bold to increase the semaphores value by one, and when the image leaves the bridge, I use the second line in bold to decrease the semaphores value by one.Code:for(;;) { Sleep(1); switch(train1.move()) { case BRIDGE_APPROACH: msgsem.wait(); display_string("Train 1 arrived at Bridge\n",2); msgsem.signal(); onbridge.signal(); break; case LEAVING_BRIDGE: msgsem.wait(); display_string("Train 1 left the Bridge\n",2); msgsem.signal(); onbridge.wait(); break;
Currently this is my only use of the semaphore, but when i run the code I recieve the following error:
I am trying to limit the number of images on the bridge to 2, and I understood that semaphores can hold a value of > than 1, so am confused why it is saying the semaphore was already at it's maximum value.Semaphore::signal
train 1 thread failed in signal semaphore (onbridge sem)
tried to increment semaphore that already was at it's maximum value.
I wanted to solve the problem by reading the semaphores value, if IF > 2, stop other images from crosing the bridge.
If anyone can offer some advice on this, I would be most greateful.
Thanks!



LinkBack URL
About LinkBacks



CornedBee