Is there a good semaphore for XNA on the XBox 360?

I am looking for a quick and effective implementation of Semaphore for the .NET Compact Framework. There was another question here about SO ( Semaphores in the .NET compact framework ), which suggested using P / Invoke, but this is not possible in the XNA Framework running on the XBox 360.

I can offer two own implementations, but both of them are suboptimal, I think.

Semaphore using AutoResetEvent (pastebin)
One possible implementation of a managed semaphore would be using AutoResetEvent.

In this case, when the work becomes available, AutoResetEvent will switch only one thread to the "runnable" state. When the OS thread scheduler starts a thread, it will open AutoResetEvent again, putting the next thread in the "runnable" state. Thus, threads will be launched sequentially, and only after their predecessor really comes to execution.

A semaphore using ManualResetEvent (pastebin)
Another possible implementation would be to use ManualResetEvent.

In this case, when the work becomes available, ManualResetEvent will put all threads in the "runnable" state. All threads executed by the OS thread scheduler will compete for work items until the first thread that does not work resets ManualResetEvent again. In other words, it is possible that all threads will be awakened for a short time, even if not all threads are required.

Does anyone know of a better implementation out there or can offer suggestions for improving mine?

+3
source share
2 answers

OpenNetCF . , OpenNetCF Xbox?

0

Source: https://habr.com/ru/post/1724945/


All Articles