public static int LocalStartThread(Thread theThread, int requestedThreadBudget, int periodIndex) { // changed the following code because can't pass int (budget) by reference. // cpuTimeInMicroseconds budget; int budget; // budget set by following call. budget = DEOSProcess.AllocateCPUBudgetForThread(theThread, requestedThreadBudget, periodIndex); if (budget > -1) { theThread.StartThread(budget); return(threadSuccess); } else { return(threadNotSchedulable); } }
public static int CreateThreadK(String name, int threadTemplateId, int threadBudget, int periodIndex) { int returnStatus; DEOSProcess currentProcess = Scheduler.CurrentProcess(); // Allocate a thread, then initialize it Thread threadCreated = new Thread(name); if (threadCreated == null) { Console.WriteLine("Thread could not be created"); returnStatus = threadMaximumThreadsExceeded; } else { // Allocate stack and initialize the thread... if (!threadCreated.ConceptualObjectConstructor(periodIndex)) { threadCreated = null; returnStatus = threadInsufficientRAMForStack; } else { int interruptState = CPU.EnterCritical(); returnStatus = LocalStartThread(threadCreated, threadBudget, periodIndex); logger.Info("{threadName}|{result}", name, returnStatus); CPU.ExitCritical(interruptState); if (threadSuccess == returnStatus) { } else { threadCreated.ConceptualObjectDestructor(); threadCreated = null; } } } return(returnStatus); }