Unsolved What is way to give highest priority to normal function over mutex based single thread in main program?
-
This post is deleted! -
@Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:
So Guide me How to give highest priority to Ticket creation function over mutex based single thread in main program ?
Mutex in single thread application?! Why?
Why do you need threads at all? -
I used Mutex in single thread is set for send data to server in background without fail . as well as when in foreground any ticket creation call happen at that time i want to add that ticket number also.
So i have to give highest priority to ticket creation in foreground and at same time i does not want to miss any sending transaction details in background.
Can you help me which theoretical concept will help me to solve this problem?
Thanks for help.
-
@Qt-embedded-developer
I cannot see why you would want mutexs in a single-threaded application. I don't understand what you are saying (and probably won't even if you clarify!).You can (try to) set thread priority via QThread::setPriority(). Though as it says there if you are using e.g. Linux it will have no effect.
One would suspect that, like many users, you are over-engineering by trying to delve into threads here. If you are performing an operation once every five minutes it's hard to see why thread priority would be an issue, and relying on thread priority to achieve/alter any behaviour is dubious.
-
it's my requirement that i have to allow create ticket functionality in foreground and at same time if Background thread is running state after 5 minute i have to give highest priority to ticket creation function.
So how to synchronize this program this code i need suggestion what i need to do?
for example conductor create ticket for passenger and at same time already generated ticket numbers i need to send to server at every 20 minute when bus is in running state.
-
@jsulm Because i have created one loop using goto statement for ticket creation and created one thread to send that data to server from background every 20 minute.
-
@Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:
using goto statement
What? goto?! Why on earth goto?!
Sorry, I really don't understand your description and don't see why you need threads. Maybe somebody else understands your descriptions better... -
My code is written like below :
void function () { check key pressed : if(IsEnterKeypressed()) createticketnumber(); else goto check key pressed; } int main() { // create thread using pthread_create which store ticket related details //from ticket db to config db. and send ticket related details to server db //a every 20 minute } void thread_fun () { // here i ask conductor that he want to generate ticket function (); //pythread_mutex_lock(); //logic of store ticket related details from ticket db to config db. and send ticket related details to server db //pythread_mutex_unlock(); }
I hope now you will understand the why i have used goto statement.
-
@Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:
I hope now you will understand the why i have used goto statement.
I do not know why you have chosen to use a
goto
statement here! :) Even if you want this code it can be written as:while (true) { if (IsEnterKeypressed()) { createticketnumber(); break; } }
Which I think is more readable/makes behaviour clearer. However, this (or your code) is an awful way to write it :( Your code runs continuously, at least until a key is pressed. Even though it is a thread, this means that thread will be using loads of CPU time. It is true that it will still allow your main UI thread to run, because it is a thread, but your computer will be permanently busy running the
while
/goto
loop.Furthermore: I don't know how your
IsEnterKeypressed()
is implemented. But assuming this interacts with the keyboard then, although I am not certain about this in Qt, I would have thought that counts as a "UI" operation and should only be done in the main UI thread, not a processing thread, as normally required in Qt.I'm sorry to say this, but every beginner-ish person here seems to think they need & understand threads, when they do not. I do not know how your system works or is intended to work, but would suggest this is not the way to do it.