Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 4012

Semaphore Question

$
0
0

So with the new preemptive threads, I’m learning all about Semaphores.

According to the documentation, a Semaphore can protect multiple resources. So let’s say you have 3 resources you want to protect when running a preemptive thread, you would call

MySempahore = New Semaphore(3)

OK, and then when you hit the first resource you want to protect you would call:

MySemaphore.Signal

And you would do the same with the second resource, etc.

But - how does the app now WHAT resource is being protected if the same semaphore is protecting multiple items? Let’s say I do this. I have 3 resources allocated for my semaphore. I have protected an object in the thread and let’s say that is resource number 2. So the Semaphore has one resource left.

Now let’s say I am doing a main thread operation and I call MySemaphore.Signal (this should success as I have one resource left) and try to then access that second object that is currently protected in the thread. What happens? I have a resource that is protected that I am trying to use but it’s now “protected” by two different semaphore calls. What happens?

27 posts - 7 participants

Read full topic


Viewing all articles
Browse latest Browse all 4012

Trending Articles