How can I declare tasks inside an ada package? - concurrency

I'm trying to write a program for a class. In the specifications, tasks cannot have any procedures or functions. I must use the package name to access Tasks. How can I go about doing this?
Can I simply write something along the lines of
package hello is
task sample is...
end sample;
end hello;

Yes.
You would of course have to put the task body in the package body.

Related

c++: how to add an environmental variable only for the current process?

Basically the question is in the title. I'm using the setenv() fucntion to set the environmental variable in my cpp program, where I also use fork() exec() chain, which create a child process. The problem is that the created variable is also accessible from this child process. This makes setenv() equivalent to export ABC=EFG behavior in the shell. What I want is to separate this functionality. I want to separately set the variable ABC=EFG and make it available to the child process export ABC. How to do this?
EDIT: I decided to add my comment to #SergeyA's answer here. How does bash handle env variables in a situation like this, for example? If I write ABC=EFG and call a script consisting from only one line echo $ABC it won't print anything unless I previously called export ABC. I'm just writing a shell and trying to mimic this behavior.
There is no direct way of doing this. Calling exec is always going to make child process inheriting environment variables of the parent process.
You can use exceve to explicitly specify environment variables to be visible to child process.

How to make UVM build_phase cooperate with build function in SVunit

I'm new to UVM and SVunit. As i'm trying to write a unit test for scoreboard, I found that if the uvm_analysis_imp port is instantiated in build phase of scoreboard and if we connect it to a uvm_analysis_port in build function of scoreboard_unit_test module, there will be a null handle problem. It seems that the build phase of scoreboard is executed later than the build() function inside module. If I put the instatiation of the uvm_analysis_imp into constructor of scoreboard, there will be no problem. But we cannot simply change the UUT to fit our test right? If I still want to keep every instatiation inside build phase, what can i do with this problem?
I think you want to instantiate the TLM ports in SV to transfer data from SVunit to UVM and also make syncrhonisation. My belive is that you cannot use uvm_analysis_imp port in SVunit, becuase SVunit just dont know what object is this.
I think you need to make the synchronisation between SVunit and UVM code in run_phase of UVM.
So you can define either some event to make their synchronisation, than use another function to transfer data. Or you can user mailbox there

How to make a gui for command-line program?

Recently, i've got interested in making a front-end for command-line program.
I guess there's two way to do it.
First one is just including source code and calling main proc with arguments
(Of course, there should be some changes in source code).
Second one, which is there's no source code and just program, is just executing program internally then reading the command line with APIs.
Though I well know about the first solution, i don't know what APIs is needed to do the second solution.
I'm talking about the APIs that get a command-line string or something like that.
See this question for information on how to run an external application; basically, you need to call CreateProcess function. I'm not sure what you mean by "reading the command line", I suppose you mean reading the output of an executed program? As for capturing an external application's output, there's already another question asking for that, you will probably find this answer most helpful.
here is a codeProject project that I have used and can handle command line arguments for you (in the setup you describe). If you are not happy with it, you can use the direct WinApi calls using CommandLineToArgvW.
Enjoy!

C++, linux: how to limit function access to file system?

Our app is ran from SU or normal user. We have a library we have connected to our project. In that library there is a function we want to call. We have a folder called notRestricted in the directory where we run application from. We have created a new thread. We want to limit access of the thread to file system. What we want to do is simple - call that function but limit its access to write only to that folder (we prefer to let it read from anywhere app can read from).
Update:
So I see that there is no way to disable only one thread from all FS but one folder...
I read your propositions dear SO users and posted some kind of analog to this question here so in there thay gave us a link to sandbox with not a bad api, but I do not really know if it would work on anething but GentOS (but any way such script looks quite intresting in case of using Boost.Process command line to run it and than run desired ex-thread (which migrated to seprate application=)).
There isn't really any way you can prevent a single thread, because its in the same process space as you are, except for hacking methods like function hooking to detect any kind of file system access.
Perhaps you might like to rethink how you're implementing your application - having native untrusted code run as su isn't exactly a good idea. Perhaps use another process and communicate via. RPC, or use a interpreted language that you can check against at run time.
In my opinion, the best strategy would be:
Don't run this code in a different thread, but run it in a different process.
When you create this process (after the fork but before any call to execve), use chroot to change the root of the filesystem.
This will give you some good isolation... However doing so will make your code require root... Don't run the child process as root since root can trivially work around this.
Inject a replacement for open(2) that checks the arguments and returns -EACCES as appropriate.
This doesn't sound like the right thing to do. If you think about it, what you are trying to prevent is a problem well known to the computer games industry. The most common approach to deal with this problem is simply encoding or encrypting the data you don't want others to have access to, in such a way that only you know how to read/understand it.

Howto call external program and get it's output from another program

Howto do this in c++:
Suppose that program A is a command line tool with some inputs (for example file paths and a number), according to it's inputs, it may get some other parameters during runtime. (if(condithin) cin<<something) I'd like to call A from another program B and want to see complete output of A during it's running. A's inputs must be entered (if necessary). B is a gui tool written with Qt and A must be shown in a plain text area and it's inputs must be shown in same place (like a console client).
I just don't know where to start. Reading something about IPC didn't help. I know it's possible because I see Dolphin's console window and python interpreter in Eric IDE...
use QProcess::execute method to start running A. you can form the argument list from B to pass to A. Use QProcess::readAllStandardOutput () to read the output of the process and display in B.
Since you use Qt, using QProcess is probably the best way to do it.