View topic - how to manage mutithread safety?

how to manage mutithread safety?

anything that doesn't fit to other groups.

how to manage mutithread safety?

Postby xuyong » Mon Jan 12, 2004 2:38 pm

in my project of one process,there are 3 threads,one is most important,it's job is to accept data for hardware,the second is to save data to file when it's necessary,the third is resposible for managing other job,how to manage them to work well?
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Postby mario » Mon Jan 12, 2004 6:04 pm

I would write them as thread, but as three different processes. Given the broad nature of your question I'l try to give a broad answer ;-) The following idea apply to both threads and processes

Hardware thread would run high priority (how high depends on what it's doing exaclty) and stuff what ever data it gather in memory ( queue) . The next thread would run low priority and only job would to empty the queue to disk. Data may need to be protected by semaphores/mutexes depending on how the data is organized in memory.


For the third thread then each type of job could get trigger by pulse each having their own priority depending on the type of job.

If it would be processes I would write the hardware part as a driver/resmgr then file buffer would be another resmgr (or just a thread in the third process) and the third one would be the main process taking to all drivers and synchronising everything, the brain if you would.

- Mario
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby xuyong » Tue Jan 13, 2004 1:48 am

I make one test,delay time of the first thread(receive data from hardware,activeted by interrupt) is very short,if I write one "printf" in it,the other thread have no chance to receive pulse,why?
xuyong
Senior Member
 
Posts: 431
Joined: Sun Mar 02, 2003 7:52 am

Postby mario » Tue Jan 13, 2004 4:21 pm

What do you mean by have no chance? Do you mean the other thread is not receiving the pulse or that it takes too much time to receive it? What pulse are you talking about, who's generating it, what priority? Sorry for all these questions but you not giving enough information and your too far away for me to try mind-reading ;-)

If I were to guess what you are asking; it's normal, if the hardware thread runs the printf at higher priority then the other thread can't receive the pulse until the hardware thread is not using the CPU, well unless you'd have a SMP system (more then 1 CPU) l-)
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron