Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm developing a multithreaded TFTP server for an exam, but i'm running into a lot of problems in finding a way to lock files (just as fcntl, flock and lockf do for processes) that works for pthreads. I think this is a typical problem, so i hope someone can suggest a "simple" solution.
Posted
Comments
tuccio 1-Apr-11 16:15pm    
pthread's rwlocks and mutexes require processes to share memory in order to work, that doesn't look simple to be honest

also that would require me to identify files on the filesystem, and mapping them with their own rwlock.. so i'd need a data structure to manage these locks, wouldn't i? or maybe i'm making it too complicated?

1 solution

Just use the provided POSIX thread synchronization mechanism (like mutex, condition variables).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Apr-11 17:01pm    
Sure; and the real problem is good architecture which I (even I :-) would not volunteer to teach in the format of quick Questions/Answers. So what... a 5 I guess. :-)
--SA
CPallini 1-Apr-11 17:57pm    
Thank you. Teaching the good architecture could be material for an article about.
tuccio 1-Apr-11 19:15pm    
Well, maybe i could do this, but i was wondering.. can i allocate a std::map on a shared memory segment i get with shmget, or i need to implement my own data structure?
lijiantao 1-Apr-11 23:36pm    
yes, you can use std::map
tuccio 2-Apr-11 7:10am    
well.. how? i mean, and how can i be sure that no memory will be allocated out of my data segment? i guess that any "new" would be a problem, isn't it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900