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

Safari web worker shows incorrect steady_clock values #4929

Closed
isaacl opened this issue Feb 7, 2017 · 5 comments
Closed

Safari web worker shows incorrect steady_clock values #4929

isaacl opened this issue Feb 7, 2017 · 5 comments
Labels

Comments

@isaacl
Copy link

isaacl commented Feb 7, 2017

steady_clock prints incorrect values in safari. chrono::system_clock does not have this issue.

Safari (wrong)

Main: elapsed 1
Worker: elapsed -71000

Chrome / Firefox:

Main: elapsed 4
Worker: elapsed 4

---Code Below---

$ cat simpleEm.cpp

#include <chrono>
#include <iostream>
#include <stdio.h>

typedef std::chrono::milliseconds::rep TimePoint;

inline TimePoint now() {
  return std::chrono::duration_cast<std::chrono::milliseconds>
        (std::chrono::steady_clock::now().time_since_epoch()).count();
}

int main() {
  TimePoint start = now();
  std::cout << "elapsed " << now() - start << "\n";
  return 0;
}
$ cat pre.js

var Module = {
  print: function(e) { postMessage(e); }
};

$ cat index.html

<head>
    <script>
      postMessage = function(msg) {
          console.log("Main: " + msg);
      }
    </script>
    <script src="a.out.js"></script>
    <script>
        var worker = new Worker('a.out.js');

        worker.addEventListener('message', function(e) {
              console.log("Worker: " + e.data);
          }, false);

        worker.postMessage('');
      </script>
</head>

build with: em++ -std=c++11 --pre-js pre.js -O3 simpleEm.cpp

emscripten 1.37.1
OS X 10.11.6
Safari 9.1.3

@kripken
Copy link
Member

kripken commented Feb 7, 2017

Hmm, this could be a safari bug? I don't have a mac to test, but that's what I'd guess. Might be best to reduce this to a small testcase using the relevant APIs and file a bug for WebKit.

@isaacl
Copy link
Author

isaacl commented Feb 9, 2017

Hmm, this could be a safari bug?

Possibly. But chrono::system_clock works fine. So I suspect emscripten_get_now_is_monotonic() is returning false.

@gauravdewan007
Copy link

High resolution clock(Performance.now) is not supported in Safari and Edge WebWorker. See the thread:
https://groups.google.com/forum/#!msg/emscripten-discuss/6sKiD-EyMxQ/CiHMqLBZAgAJ
There is simple polyfill work-around.

@isaacl
Copy link
Author

isaacl commented Feb 15, 2017

Is this an emscripten bug? (using the wrong time source)

@stale
Copy link

stale bot commented Aug 30, 2019

This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Aug 30, 2019
@stale stale bot closed this as completed Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants