ти синхронізацію між споживачем і виробником. br/>
10. Лістинг програми
синхронізація виробник сигнал буфер
////////////////////////////////////////// ////////////////////////
//
// RtxApp1.c - C file
//
////////////////////////////////////////// ////////////////////////
# include "RtxApp1.h" mutex; items; spaces; GasStation = 20; lReleaseCount = 1; Bubble; BubbleM; Plus = 3; Minus = 4;
# define MSGSTR_SEM "Sem"
# define MUTEX_ENABLEDRTFCNDCL Thread1Cycle (PVOID unused)
{(1)
{(mutex, INFINITE);
{= GasStation + Plus; (Bubble <20)
{+ = Plus; ("(PRODUCER) GIVE =% d", Plus); ("(Fuel level =% d n", GasStation);
} (Bubble> 20)
{("(PRODUCER) want GIVE =% d", Plus); ("Fuel level will be FULL, wait =% d n", GasStation);
} (Bubble == 20)
{+ = Plus; ("(PRODUCER) GIVE =% d", Plus); ("Fuel level is FULL =% d n", GasStation);
} (3000); (mutex, lReleaseCount, NULL);
}
} NO_ERRORS;
} RTFCNDCL Thread2Cycle (PVOID unused)
{(1)
{(mutex, INFINITE);
{(10); = rand ()% 10; = GasStation - Minus; (BubbleM> 0)
{- = Minus; ("(CONSUMER) TAKE =% d", Minus); ("Fuel level =% d n", GasStation);
} (BubbleM <0)
{("(CONSUMER) want TAKE =% d", Minus); ("(CONSUMER) Need more GAS, wait =% d n", GasStation);
} (BubbleM == 0)
{- = Minus; ("(CONSUMER) TAKE =% d", Minus); ("Fuel level is EMPTY =% d n", GasStation);
} (3000); (mutex, lReleaseCount, NULL);
}
} NO_ERRORS;
} _cdecl wmain (int argc, wchar_t ** argv, wchar_t ** envp)
{
// for periodic timer code_INTEGER liPeriod;// timer period_INTEGER time; hTimer = NULL;// timer handlethreadId; dwStackSize = 0; stackSize = 0; sleepTime = 30000; dwExitCode = 0; (" n ");
//
// Create the thread.
// = CreateThread (,,// ​​defaultCycle,// ​​function,// ​​parameters_SUSPENDED,
& threadId
); (hThread1 == NULL)
{("Error: could not create thread. GetLastError =% d n", GetLastError ()); ERROR_OCCURED;
} (! RtSetThreadPriority (hThread1, RT_PRIORITY_MAX))
{("Error: could...