Semaphore

This forum is for general developer support questions.

Semaphore

Postby dstastny » Thu Jan 12, 2017 10:09 pm

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
dstastny
 
Posts: 20
Joined: Fri Dec 16, 2016 7:31 am
Location: Atlanta GA

Re: Semaphore

Postby tonyw » Fri Jan 13, 2017 12:23 am

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
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 1204
Joined: Wed Mar 09, 2011 2:36 pm
Location: Sydney, Australia

Re: Semaphore

Postby ssolie » Fri Jan 13, 2017 1:15 am

There is also documentation on Semaphores here:
http://wiki.amigaos.net/wiki/Exec_Semaphores
AmigaOS Development Team Lead
Be authentic. Get AmigaOS.
User avatar
ssolie
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 1000
Joined: Mon Dec 20, 2010 9:51 pm
Location: Canada

Re: Semaphore

Postby tboeckel » Fri Jan 13, 2017 9:42 am

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.
User avatar
tboeckel
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 67
Joined: Mon Jun 20, 2011 9:56 am

Re: Semaphore

Postby dstastny » Fri Jan 13, 2017 3:41 pm

@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
dstastny
 
Posts: 20
Joined: Fri Dec 16, 2016 7:31 am
Location: Atlanta GA


Return to General Developer Support

Who is online

Users browsing this forum: No registered users and 1 guest