Apr 9, 2020 02:17 AM
(This post was last modified: Apr 9, 2020 04:47 AM by zNinja.)
I am trying to implement my own event loop for my project.
I notice that sometimes, like once in 30 runs, one of threads is blocking the main thread on thread.join method.
I am trying to understand why.
Code is interesting, not too big, but is small to post it here.
So I will put a github link where file is uploaded.
GitHubLink
Valid output is similar to this
Goal is to all Thread object have been destructed successfully by having " thread out 0" eventually in program output.
Invalid output similar to this
Btw, this is code from scrach. To see if concept can work or not before implementing it into library for use case.
Any help is welcome.
In Thread object on calling the join is blocking.
Thread is abstract class of EventLoop object. Problem is probably in "run" method of EventLoop object but I am not able to figure out exactly where and why.
I can not see any dead lock so far.
Edit.
Oh, so sorry. I realize just now I did not write on c/c++ section.
If any can move this tropic to c/c++.
I notice that sometimes, like once in 30 runs, one of threads is blocking the main thread on thread.join method.
I am trying to understand why.
Code is interesting, not too big, but is small to post it here.
So I will put a github link where file is uploaded.
GitHubLink
Valid output is similar to this
PHP Code
<?php
thread in : lock:11
thread in : 2
lock:1
thread in : 3
lock:1
thread in : 4
lock:1
thread in : 5
lock:1
lock:1
unlock
lock:1
unlock
thread hello world
unlock
unlock
lock:1
unlock
unlock
unlock
unlock
join
join done
thread out: 4
join
join done
thread out: 3
lock:1
unlock
join
join done
thread out: 2
join
join done
thread out: 1
join
join done
thread out: 0
lock:1
Goal is to all Thread object have been destructed successfully by having " thread out 0" eventually in program output.
Invalid output similar to this
PHP Code
<?php
thread in : 1
thread in : 2
thread in : 3
thread in : 4
thread in : 5
lock:1
unlock
lock:1
lock:1
lock:1
unlock
thread hello world
unlock
join
lock:1
unlock
lock:1
unlock
lock:1
lock:1
Btw, this is code from scrach. To see if concept can work or not before implementing it into library for use case.
Any help is welcome.
In Thread object on calling the join is blocking.
Thread is abstract class of EventLoop object. Problem is probably in "run" method of EventLoop object but I am not able to figure out exactly where and why.
I can not see any dead lock so far.
Edit.
Oh, so sorry. I realize just now I did not write on c/c++ section.
If any can move this tropic to c/c++.

