File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # This file is part of NIT ( http://www.nitlanguage.org ).
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ # This test shows the verification of contracts in a parallel execution.
16+
17+ import pthreads
18+
19+ fun foo is
20+ threaded
21+ expect (contract_foo )
22+ do
23+ print "Foo "
24+ bar ("Foo thread " )
25+ end
26+
27+ fun bar (thread_name : String )
28+ is
29+ threaded
30+ expect (contract_bar (thread_name ))
31+ do
32+ print "Bar called from {thread_name } "
33+ end
34+
35+ fun contract_foo : Bool
36+ do
37+ print ("Foo contract " )
38+ return true
39+ end
40+
41+ fun contract_bar (thread_name : String ): Bool
42+ do
43+ sys .nanosleep (3 ,0 )
44+ print ("Bar contract called from {thread_name } " )
45+ return true
46+ end
47+
48+
49+ foo
50+ sys .nanosleep (1 ,0 )
51+ bar ("Main thread " )
52+ sys .nanosleep (5 ,0 )
Original file line number Diff line number Diff line change 1+ Foo contract
2+ Foo
3+ Bar contract called from Foo thread
4+ Bar called from Foo thread
5+ Bar contract called from Main thread
6+ Bar called from Main thread
You can’t perform that action at this time.
0 commit comments