Slow pthread conditionals

62 views
Skip to first unread message

SK

unread,
May 7, 2021, 8:13:16 PM5/7/21
to emscripten-discuss
Hello,

With latest EMSDK 2.0.20 I'm trying to use wait and signal using pthread_cond_signal() and pthread_cond_wait() functions.

I'm consistently seeing this issue between two non-UI threads that after a pthread_cond_signal() , a previously waiting pthread_cond_timedwait() only comes out after 1-2 seconds delay, expectation is that it should be ready at max within the scheduling interval.

The first row shows time just before entering wait(), later are pairs of times of when actual event is generated and point just before signal() is called, there's barely any difference. Many such events pass until we come out of wait and see the last 'Post wait' is printed, it takes 1.56 seconds to return even though event is already signaled. All times are epoch times retrieved via clock_gettime(CLOCK_REALTIME, ...) option.

Wait start time 1620415241.405

Event generation time 1620415241.859  0.454
Signaling time 1620415241.859 0.454

Event generation time 1620415242.300 0.895
Signaling time 1620415242.300 0.895

Event generation time 1620415242.329 0.924
Signaling time 1620415242.329 0.924

Event generation time 1620415242.465 1.060
Signaling time 1620415242.465 1.060

Event generation time 1620415242.738 1.333
Signaling time 1620415242.738 1.333

Event generation time 1620415242.833 1.428
Signaling time 1620415242.833 1.428

Event generation time 1620415243.163 1.758
Signaling time 1620415243.163 1.758

Event generation time 1620415243.248 1.843
Signaling time 1620415243.249 1.844

Post wait time 1620415243.418 2.013 1.559

Any pointers would be greatly appreciated.

Thanks,
Sarang.

Sarang Karandikar

unread,
May 10, 2021, 3:48:19 PM5/10/21
to emscripte...@googlegroups.com
For easier reading, this is what is happening:

--------------------------------------------------------------------------------
Thread T1(UI Thread)                    | Thread T2 (Non UI Thread)             |
----------------------------------------|---------------------------------------
[A] PrintTime(); pthread_cond_wait()    |                                       |
                                        | [X] PrintTime(); pthread_cond_signal()|
                                        |                                       |
[B] PrintTime();                        |                                       |
--------------------------------------------------------------------------------

The current times printed at [A] [X] and [B] are:
[A]: t0
[X]: t0 + k
[B]: t0 + k + [1 second - 2 seconds],
                                        
The extra delay of 1-2 seconds at
[B] is the issue, ideally it should be no more
than the scheduler delay (10-15 ms).

Thanks,
Sarang.



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/0e73db37-aa12-43fc-948e-ef9622f2dc03n%40googlegroups.com.

Sam Clegg

unread,
May 10, 2021, 6:55:39 PM5/10/21
to emscripte...@googlegroups.com
When performing these measurements, you may want to do your recordings to linear memory and then print them afterwards.   I think that stdout (printf) willould affect your measurements as gets proxied back through the main thread.  

Sarang Karandikar

unread,
May 18, 2021, 6:45:58 PM5/18/21
to emscripte...@googlegroups.com
It turns out that it was an incorrect assumption, the signalled thread does become active within 20ms when the DevTools window is hidden.

Thanks,
Sarang.

Reply all
Reply to author
Forward
0 new messages