Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latch & barrier #15

Closed
samchon opened this issue Nov 9, 2018 · 3 comments
Closed

latch & barrier #15

samchon opened this issue Nov 9, 2018 · 3 comments
Labels
C++20 enhancement New feature or request help wanted Extra attention is needed

Comments

@samchon
Copy link
Owner

samchon commented Nov 9, 2018

Latch and Barrier are thread supporting classes who can block critical sections with downward counter. They're strong candidates who may come into the C++20 revision. Thus, it would better to implement them into the experimental namespace.

Latch

The Latch class locks a critical section until its downward counter to be zero.

namespace std.experimental
{
    export class Latch
    {
        public constructor(size: number);

        public is_ready(): boolean;
        public arrive(n: number = 1): Promise<void>;
        public arrive_and_wait(): Promise<void>;

        public wait(): Promise<void>;
        public wait_for(ms: number): Promise<boolean>;
        public wait_until(at: Date): Promise<boolean>;
    }
}

Barrier

The Barrier class can re-use the downward counter..

namespace std.experimental
{
    export class Barrier extends FlexBarrier
    {
        public constructor(size: number);
    }

    export class FlexBarrier
    {
        public constructor(size: number);
        public constructor(size: number, completion: () => number);

        public arrive_and_wait(): Promise<void>;
        public arrive_and_drop(): Promise<void>;

        public try_arrive(): Promise<boolean>;
        public wait(): Promise<void>;
        public wait_for(ms: number): Promise<boolean>;
        public wait_until(at: Date): Promise<boolean>;
    }
}
@samchon samchon changed the title [C++20] Latch & Barrier [New Feature] Latch & Barrier Nov 9, 2018
@samchon samchon added enhancement New feature or request help wanted Extra attention is needed v2.1 labels Nov 10, 2018
@samchon samchon changed the title [New Feature] Latch & Barrier Latch & Barrier Nov 10, 2018
@samchon samchon changed the title Latch & Barrier latch, barrier and flex_barrier Nov 10, 2018
@samchon samchon changed the title latch, barrier and flex_barrier Latch & Barrier Nov 10, 2018
@samchon samchon added C++20 and removed enhancement New feature or request labels Nov 10, 2018
@samchon
Copy link
Owner Author

samchon commented Nov 10, 2018

Class Source File
Latch https://github.com/samchon/tstl/blob/v2.1/src/experimental/thread/Latch.ts
Barrier https://github.com/samchon/tstl/blob/v2.1/src/experimental/thread/Barrier.ts
FlexBarrier https://github.com/samchon/tstl/blob/v2.1/src/experimental/thread/FlexBarrier.ts

I've implemented and published those latch & barrier features with the @next tag. I think Latch is implemented exactly, however, I can't sure that Barrier and FlexBarrier are exact. I don't know the exact specs and definitions of those features. Can anyone help me?

@samchon samchon changed the title Latch & Barrier latch & barrier Nov 12, 2018
@samchon samchon removed the v2.1 label Nov 13, 2018
@samchon samchon added this to In progress in v2.1 Update Nov 13, 2018
@samchon samchon moved this from In progress to Done in v2.1 Update Nov 30, 2018
@samchon samchon moved this from Done to On review in v2.1 Update Nov 30, 2018
@samchon samchon moved this from On review to Done in v2.1 Update Dec 11, 2018
@samchon samchon added the enhancement New feature or request label Dec 11, 2018
@samchon samchon closed this as completed Dec 12, 2018
@samchon samchon added the experimental Experimental Feature label Apr 6, 2019
@samchon
Copy link
Owner Author

samchon commented Aug 9, 2019

latch and barriers are now regular features in the C++20. They must be escaped from the experimental features.

@samchon samchon reopened this Aug 9, 2019
@samchon samchon added this to To do in v2.3 Update via automation Aug 9, 2019
@samchon samchon moved this from To do to In progress in v2.3 Update Aug 11, 2019
@samchon
Copy link
Owner Author

samchon commented Aug 17, 2019

https://github.com/cplusplus/draft/blob/master/papers/n4830.pdf

Definition of latch and barriers are fixed like below:

Latch

namespace std
{
    export class Latch
    {
        public constructor(size: number);

        public count_down(): Promise<void>;
        public arrive_and_wait(): Promise<void>;

        public try_wait(): Promise<boolean>;
        public wait(): Promise<void>;
        public wait_for(ms: number): Promise<boolean>;
        public wait_until(at: Date): Promise<boolean>;
    }
}

Barrier

namespace std
{
    export class Barrier extends FlexBarrier
    {
        public constructor(size: number);
    }

    export class FlexBarrier
    {
        public constructor(size: number);
        public constructor(size: number, completion: () => number);

        public arrive(n: number = 1): Promise<void>;
        public arrive_and_wait(): Promise<void>;
        public arrive_and_drop(): Promise<void>;
        public wait(): Promise<void>;
    }
}

samchon pushed a commit that referenced this issue Aug 17, 2019
v2.3 Update automation moved this from In progress to Done Sep 28, 2019
@samchon samchon removed the experimental Experimental Feature label Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++20 enhancement New feature or request help wanted Extra attention is needed
Projects
No open projects
v2.1 Update
  
Done
v2.3 Update
  
Done
Development

No branches or pull requests

1 participant