seem don't wait the end of the group
let oneSem_1 = DispatchSemaphore(value: 1)
let semaphore = DispatchSemaphore(value: 4)
let semaphoreEND = DispatchSemaphore(value: 0)
var p=0
let group_2 = DispatchGroup()
var t:[Int]=[]
let MAX=1000000
for _ in 0..<MAX {
    group_2.enter()
    DispatchQueue.global().async{
        //group_2.enter()
        semaphore.wait()
        oneSem_1.wait()
        p+=1
        t.append(p)//car ressource critique, sinon pas rempli à fond
        oneSem_1.signal()
        if p == MAX{
            print("p == MAX")
            semaphoreEND.signal()
        }
        semaphore.signal()
        //group_2.leave()
    }
    group_2.leave()
}
group_2.wait()
//    semaphoreEND.wait()
//    while(p != MAX){
//        usleep(1_00_000)
//        print("p=",p)
//    }
print("END   p=\(p)  t.count=\(t.count)")
I expect the output of ND p=1000000 t.count=1000000
I can get this result if i uncomment // semaphoreEND.wait()
, but the actual output is
END p=999871 t.count=999881
Other problem : t.count != p
With Group i expect the end of all task. Why i have to uncomment // semaphoreEND.wait() ?
Thanks
Project here for download : https://github.com/fredOnGitHub/semaphore_to_modify_1
