linux - How to pass new messages to the thread function on run time? -



linux - How to pass new messages to the thread function on run time? -

in pthread_create can specify 1 message, on run time may new messages need passed thread printing.

one way may create global vector, , maintain on adding messages it. thread fetch vector , scan new messages. in way n vectors have created n threads! or 1 construction threadid, message, , print status.

what possible practical ways out?

edit 1:

is next design fine or needs improvements?

the next code written in normal function called main().

check if thread (responsible grabbing message) there.

if yes, force message in thread's queue, wake thread (pthread_cond_signal()). if no, create thread, create queue, force message in queue.

when thread finishes reading messages in queue, allow sleep (pthread_cond_wait()).

google 'pthreads producer consumer queue'. should not need scan new entries - producer/s signal consumer thread new entries available.

linux multithreading pthreads

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -