> On Oct 7, 2016, at 9:06 PM, Gerriet M. Denkmann wrote:
>
> My preferred way to count (not deprecated and fast, but, as you said,
> probably not available in Swift) is:
>
> #import
> atomic_uint_fast64_t counter;
> atomic_fetch_add_explicit( &counter, 1, memory_order_relaxe
> On Oct 7, 2016, at 10:05 AM, Quincey Morris
> wrote:
>
> Surely “anyone reading the code” is going to recognize “dispatch_semaphore”
> as something to do with a semaphore, including people from other platforms?
You’re right; I was [mis]remembering a classic semaphore as being a simple
mute
> On 8 Oct 2016, at 11:22, Quincey Morris
> wrote:
>
> On Oct 7, 2016, at 21:06 , Gerriet M. Denkmann wrote:
>>
>> But, alas, it is also much slower: overhead almost 40 sec (whereas my
>> admittedly rather hackish way took less then half a second).
>
> That may indicate a lot of contention
On Oct 7, 2016, at 21:06 , Gerriet M. Denkmann wrote:
>
> But, alas, it is also much slower: overhead almost 40 sec (whereas my
> admittedly rather hackish way took less then half a second).
That may indicate a lot of contention — e.g. you were running multiple copies
of that loop in different
> On 8 Oct 2016, at 05:01, Quincey Morris
> wrote:
>
> On Oct 7, 2016, at 07:49 , Gerriet M. Denkmann wrote:
>>
>> Is there a better way than this:
>> dsema = dispatch_semaphore_create( 0 );
>>
>> some loop to be counted
>> {
>> dispatch_semaphore_signal(dsema);
>>
On Oct 7, 2016, at 15:37 , Dave Fernandes wrote:
>
> But I don’t see how incrementing it after creating it is any different from
> creating it with a non-zero count. Either way, if you have resources
> available, the count will be non-zero, and you will crash if you try to
> deallocate.
The d
>
> In practice, you’d actually initialize the semaphore like this:
>
>> dsema = dispatch_semaphore_create (0); // start with a zero count
>> dispatch_semaphore_signal (dsema); // increment to the number of
>> resources in the pool.
>
> That’s because if you create the semaphore with
On Oct 7, 2016, at 07:49 , Gerriet M. Denkmann wrote:
>
> Is there a better way than this:
> dsema = dispatch_semaphore_create( 0 );
>
> some loop to be counted
> {
> dispatch_semaphore_signal(dsema);
> ….
> }
>
> NSUInteger counter = 0;
> for(;;)
> {
> long a
On Fri, Oct 7, 2016, at 11:24 AM, Jens Alfke wrote:
>
> > On Oct 7, 2016, at 1:14 AM, Quincey Morris
> > wrote:
> >
> > One straightforward way is to use dispatch_semaphore. IIRC it’s lightweight
> > unless it blocks (that is, unless its count is zero when you wait), so it’s
> > good for th
On Oct 7, 2016, at 09:24 , Jens Alfke wrote:
>
> IMO dispatch_semaphore is overkill for this; it’s not just an atomic counter,
> it’s also got blocking behaviors for use in e.g. managing a pool of resources.
I wasn’t suggesting using dispatch_semaphore itself as the atomic counter, but
rather
> On Oct 7, 2016, at 1:14 AM, Quincey Morris
> wrote:
>
> One straightforward way is to use dispatch_semaphore. IIRC it’s lightweight
> unless it blocks (that is, unless its count is zero when you wait), so it’s
> good for this situation where actual contention is rare (assuming actual
> con
On 7 Oct 2016, at 08:19, Gerriet M. Denkmann wrote:
> So what is the proper way to count something atomicly and undeprecatedly?
or is the approved source for this kind of thing.
In C++, you might write
#include
std::atomic counter;
then you can just do
++counter;
--counter;
as u
> On 7 Oct 2016, at 15:14, Quincey Morris
> wrote:
>
> On Oct 7, 2016, at 00:19 , Gerriet M. Denkmann wrote:
>>
>> So what is the proper way to count something atomicly and undeprecatedly?
>
> One straightforward way is to use dispatch_semaphore. IIRC it’s lightweight
> unless it blocks (th
> On 7 Oct 2016, at 15:43, Ken Thomases wrote:
>
> On Oct 7, 2016, at 2:19 AM, Gerriet M. Denkmann wrote:
>>
>> I need (just for debugging purposes) to count something in a thread safe
>> way.
>> […]
>> So I tried OSIncrementAtomic.
>> Now I get: "Implicit declaration of function 'OSIncremen
On Oct 7, 2016, at 2:19 AM, Gerriet M. Denkmann wrote:
>
> I need (just for debugging purposes) to count something in a thread safe way.
> […]
> So I tried OSIncrementAtomic.
> Now I get: "Implicit declaration of function 'OSIncrementAtomic' is invalid
> in C99" and the linker fails, because it
On Oct 7, 2016, at 00:19 , Gerriet M. Denkmann wrote:
>
> So what is the proper way to count something atomicly and undeprecatedly?
One straightforward way is to use dispatch_semaphore. IIRC it’s lightweight
unless it blocks (that is, unless its count is zero when you wait), so it’s
good for t
I need (just for debugging purposes) to count something in a thread safe way.
This works, but is deprecated:
SInt32 counter;
- (IBAction)doSomething:sender
{
counter = 0;
some loop
{
IncrementAtomic( &counter );// 'IncrementAtomic' is
d
17 matches
Mail list logo