Semaphore

This forum is for general developer support questions.
Post Reply
dstastny
Posts: 42
Joined: Fri Dec 16, 2016 6:31 am
Location: Atlanta GA

Semaphore

Post 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

User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1433
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: Semaphore

Post 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.
cheers
tony

User avatar
ssolie
Beta Tester
Beta Tester
Posts: 1010
Joined: Mon Dec 20, 2010 8:51 pm
Location: Canada
Contact:

Re: Semaphore

Post by ssolie »

There is also documentation on Semaphores here:
http://wiki.amigaos.net/wiki/Exec_Semaphores
ExecSG Team Lead

User avatar
tboeckel
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 68
Joined: Mon Jun 20, 2011 8:56 am
Contact:

Re: Semaphore

Post 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.

dstastny
Posts: 42
Joined: Fri Dec 16, 2016 6:31 am
Location: Atlanta GA

Re: Semaphore

Post 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

Post Reply