Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++ Threads question

Started by BombShell Mar 10, 2004 at 8:29 AM 3 replies 450+ views
Original Post
BombShell
BombShell
Hi all, In C++, can one specify that a piece of code in a thread always has to be executed as a whole (i.e. the control must not switch from this thread to another one when it is executing this specific piece of code)? I am doing some timing in a thread, and this code should always be executed as a whole, otherwise (obviously) the timing would be wrong. Is this possible? Anyone any ideas? Thanks in advance! PS I am already using Mutexes for controlling the access to shared variables and resources. Greetings, BombSheLL
amag
amag
Depends on your OS, in DOS this is quite doable, in Windows >= 95, then no, you're out of luck. That's the meaning of *pre-emptive* multitasking (a thread can lose control anytime).

[edited by - amag on March 10, 2004 9:35:50 AM]
Agony
Agony
I''m almost 100% confident that there''s no C++ specific way. You''d have to use whatever the OS provides. Especially if you want a chunk of code to execute all at once, even preventing the threads of other processes from running. Although at that point, I don''t know if something like that is even available from the OS.


int main() { return *((int*)0); }
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
BombShell
BombShell
Yes I''m using Win32, and all threads belong to the same process, so Critical sections would indeed be more efficient than mutexes. However I''m using the JThread library (lumumba.luc.ac.be/~jori), which only supports mutexes and not critical sections.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.