Repository navigation
std::this_thread::sleep_for(std::chrono::milliseconds) #788
Description
Activity
nope, it's just there as an example of a task that blocks while the main thread continues to run
Reacted by Nicola Del GobboI tired with thread safe function example with my native code in it and I didn't give any sleep in the code when I am running the code in simply exiting without any execution.
But when i give some sleep after calling the call back for some time it executing and stoped,
// Create a ThreadSafeFunction
tsfn = ThreadSafeFunction::New(
env,
info[0].As(), // JavaScript function called asynchronously
"Resource Name", // Name
0, // Unlimited queue
1, // Only one thread will use this initially
{ // Finalizer used to clean threads up
nativeThread.join();
});// Create a native thread nativeThread = std::thread([async_stream_data_ex] { auto callback = [](Napi::Env env, Function jsCallback, BaseMessageData* BMD) { Object local_obj = Object::New(env); /*Object js_obj = Object::New(env); BMDToJSObj(env, local_obj, BMD);*/ BMDToJSObj(env, local_obj, BMD); Object js_obj = Object::New(env); js_obj.Set("Message", local_obj); // Transform native data into JS data, passing it to the provided // `jsCallback` -- the TSFN's JavaScript function. jsCallback.Call({ js_obj }); }; StreamReadStatus srs; async_stream_data_ex->pAdvDecoder->EnableUnknownData(TRUE); do { BaseMessageData *BMD = NULL; UINT msgid; srs = async_stream_data_ex->pAdvDecoder->ReadMessage(&BMD); if (srs.bEOS == false) { if (tsfn.Acquire() == napi_ok) { if (BMD->IsAdvancedMessage() == TRUE) { napi_status status = tsfn.BlockingCall(BMD, callback); tsfn.Release(); } else { napi_status status = tsfn.BlockingCall(BMD, callback); tsfn.Release(); } } } delete BMD; BMD = NULL; } while (srs.bEOS == false); // Release the thread-safe function //tsfn.Release(); });This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
@srikanthkampati you might want to try recreating with the latest to see if #853 fixed it and if not and seeing if nodejs/node#36510 is related
Is it mandatory to call sleep in the thread after calling a callback function?