Page 1 of 1

Semaphore

Posted: Thu Jan 12, 2017 9:09 pm
by dstastny
I am not sure if I am just missing something in the documentation but is there some way to specify a count on a Semaphore like a Posix Semaphore or Windows Semaphore. From what I can see it looks like it only support a count of 1. I have seen some implementations using PThreads but I was hoping to create a native implementation so I can control the tasks with pause and restart which is missing from PThreads. I'm trying to implement a ThreadPool like functionality.

Thanks
Doug

Re: Semaphore

Posted: Thu Jan 12, 2017 11:23 pm
by tonyw
If you look up the "struct SignalSemaphore" in SDK:include/include_h/exec/semaphores.h, you will see the two 16-bit counts, one for the task that currently "owns" the semaphore and the other for the queue of other tasks waiting for it.

The nesting/counting action is described in SDK:Documentation/AutoDocs/exec.doc/ObtainSemaphore.

Re: Semaphore

Posted: Fri Jan 13, 2017 12:15 am
by ssolie
There is also documentation on Semaphores here:
http://wiki.amigaos.net/wiki/Exec_Semaphores

Re: Semaphore

Posted: Fri Jan 13, 2017 8:42 am
by tboeckel
Our semaphores more or less match what other system call a "mutex", i.e. something that can be obtained once only. In contrast to a mutex the semaphore of other systems can be obtained up to n times in parallel, but the n+1 accessor will be blocked until one of the first n releases the semaphore again. This is something that the struct SignalSemaphore of AmigaOS cannot provide (yet). At least this is how I understand the situation.

Re: Semaphore

Posted: Fri Jan 13, 2017 2:41 pm
by dstastny
@All - I appreciate the replies.
@tboeckel - That was my understanding from documentation but thought I might have missed something.

I will look into rolling my own. I know it can be done from what I have read with condition variable and a mutex as I have seen some implementations with pthreads. I was hoping to keep it native.

Regards
Doug