c++ - C++11 deferred "thread" creation (i.e., specify thread function but do not wait physical thread to be created) -
my goal asked in title want caller thread not wait child thread physically created , resumed when using std::thread ctor thread function (non void ctors)
my problem hits (in windows) when try create std::thread object thread function during dll load. problem because (as far beleive) - thread constructor tries create physical thread - ctor somehow (and unluckly me) waits physical trhread resume (go live) - unfortunately, win api not allow threads resume within loadlibrary call if created during function call. - have dead-lock: loadlibrary creates thread, waits resume, windows not let resume.
i can invent solutions problem (by having distinct thread not using std::thread constructing additional threads (std::threads), miss whole point of using "only" std::thread threading needs :-) ). however, best if std::thread told not wait physical thread resume if constructed thread function (or lambda or whatever). there way of doing or should go work-arounds? thanks
- one more case when 1 need same in fast path, may create (lazyly) std::thread object, post tasks (many tasks potentiall), , go-on (in fast path) without getting delayed! may not care when child thread physically gets created , resumes. pitty if 1 cannot lazly have physical threads created in such fast-pathes or during dllmain etc.
the problem not in way creating thread, rather in fact creating thread while dll being loaded. while calls createthread
may safe (as long no waiting operations performed launched thread), it in general bad idea create threads during dllmain
.
what should here export initializer function , require loading modules invoke after dll has been loaded. initializer function instantiate required objects , create necessary threads.
also see this q&a on stackoverflow.
Comments
Post a Comment