Home > Software engineering >  Reading and writing of a problem
Reading and writing of a problem

Time:04-15

I have a circular linked list, each child thread only need to read the data in the linked list nodes, but there are times when the main thread to rewrite cycle node in the list,
Every time I design train of thought is the main thread to rewrite the linked list node need to enter the critical section, rewrite the complete leave, consult bosses read the child thread linked list node data may not be critical section? If you need to add critical region, then assign each child thread a circular linked list whether efficiency will be higher? (if need to use TLS, so the main thread to access each thread in the TLS circular linked list?)

CodePudding user response:

Lock safer, but efficiency is not high, can know about the read-write lock;
Assign each child thread a circular linked list, also involves the data synchronization problem, efficiency should be even worse

CodePudding user response:

Modify the data of the main thread is only one? If the child thread without didn't need to add the main thread, because modify the data of the main thread is only one, no one to grab it, there is no conflict,
You are communal circular linked list data? If it is a common, you assign to each child thread a circular linked list, so the main thread all child threads need to update the list every time, every time want to compete with all the child thread, a list of words is the main thread, competition between all the child thread; Multiple chain table is the main thread and the competition between each child threads, feel less than where high efficiency,

CodePudding user response:

refer to the second floor tiger bobo response:
modify the data of the main thread is only one? If the child thread without didn't need to add the main thread, because modify the data of the main thread is only one, no one to grab it, there is no conflict,
You are communal circular linked list data? If it is a common, you assign to each child thread a circular linked list, so the main thread all child threads need to update the list every time, every time want to compete with all the child thread, a list of words is the main thread, competition between all the child thread; Multiple chain table is the main thread and the competition between each child threads, feel less than where high efficiency,

Ok thank you advice!

CodePudding user response:

Ok thank you advice!

CodePudding user response:

refer to the second floor tiger bobo response:
modify the data of the main thread is only one? If the child thread without didn't need to add the main thread, because modify the data of the main thread is only one, no one to grab it, there is no conflict,
You are communal circular linked list data? If it is a common, you assign to each child thread a circular linked list, so the main thread all child threads need to update the list every time, every time want to compete with all the child thread, a list of words is the main thread, competition between all the child thread; Multiple chain table is the main thread and the competition between each child threads, feel less than where high efficiency,

To reconfirm! My child thread is the while (1) continue to read the circulation data in the list the main thread may modify circular linked list but only the main thread to modify it without critical area

CodePudding user response:

Only one thread to modify a Shared resource, don't need to add other threads just read, do not affect

CodePudding user response:

reference 1st floor sevancheng response:
lock safer, but efficiency is not high, can know about the read-write lock;
Assign each child thread a circular linked list, also involves the data synchronization problem, poor efficiency should be more

Read/write locks are positive solutions
  • Related