i'm not sure eventwaithandle.set. when called within current thread , there thread waiting event, current thread sleep other thread gets run (asap)?
i'm asking because in of code have add object "threads shared" queue , operation has go quick possible. in other thread queue being used, speed "not required". i'm proceeding this:
// speed "not required" mailthread = new task(() => { (; ; ) { mailmessage mail; pushmaillockmrevt.waitone(); { if (mails.count == 0) { mail = null; } else { mail = mails.dequeue(); } } pushmaillockmrevt.set(); // put current on sleep on lower it's priority?? if (mail != null) { try { mailclient.send(mail); } catch (exception exe) { } } else { mailsem.waitone(); } } }); [...] // speed required var task = new task(() => { pushmaillockmrevt.waitone(); // asap please... { mails.enqueue(mailmessage); if (mails.count == 1) { mailsem.set(); } } pushmaillockmrevt.set(); });
no, current thread not sleep because signals wait handle. may relinquish rest of timeslice (that's pretty subtle , low-level , isn't should rely on). should not need take special action.
it case thread has finished waiting will brief boost in thread priority.
see this documentation windows api function setthreadpriorityboost()
quote:
when thread running in 1 of dynamic priority classes, system temporarily boosts thread's priority when taken out of wait state.
also see this documentation.
so thread woke wait should (normally) small boost. i'm not totally sure applies managed threads, seem remember reading somewhere does. can't find source of that, though.
Comments
Post a Comment